るりまサーチ

最速Rubyリファレンスマニュアル検索!
109件ヒット [1-100件を表示] (0.086秒)
トップページ > ライブラリ:ビルトイン[x] > クエリ:p[x] > クエリ:class[x] > クエリ:UnboundMethod[x]

別のキーワード

  1. openssl p
  2. openssl p=
  3. fileutils mkdir_p
  4. kernel p
  5. _builtin p

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

UnboundMethod (38062.0)

レシーバを持たないメソッドを表すクラスです。 呼び出すためにはレシーバにバインドする必要があります。

...より生成し、後で
UnboundMethod
#bind によりレシーバを
割り当てた Method オブジェクトを作ることができます。

//emlist[例: Method クラスの冒頭にある例を UnboundMethod で書くと以下のようになります。][ruby]{
class
Foo
def foo() "foo" end...
...ならない)
p
methods[1].bind(Foo.new).call # => "foo"
p
methods[2].bind(Foo.new).call # => "bar"
p
methods[3].bind(Foo.new).call # => "baz"
//}

//emlist[例: 以下はメソッドの再定義を UnboundMethod を使って行う方法です。普通は alias や super を使いま...
...す。][ruby]{
class
Foo
def foo
p
:foo
end
@@orig_foo = instance_method :foo
def foo
p
:bar
@@orig_foo.bind(self).call
end
end

Foo.new.foo

# => :bar
# :foo
//}...

UnboundMethod#bind(obj) -> Method (21092.0)

self を obj にバインドした Method オブジェクトを生成して返します。

...トを生成して返します。


@param obj 自身をバインドしたいオブジェクトを指定します。ただしバインドできるのは、
生成元のクラスかそのサブクラスのインスタンスのみです。

@raise TypeError objがbindできないオブジ...
...タンスメソッドの UnboundMethod の場合
class
Foo
def foo
"foo"
end
end

# UnboundMethod `m' を生成
p
m = Foo.instance_method(:foo) # => #<UnboundMethod: Foo#foo>

# Foo のインスタンスをレシーバとする Method オブジェクトを生成
p
m.bind(Foo.new)...
...Method
class
Bar < Foo
end
p
m.bind(Bar.new) # => #<Method: Bar(Foo)#foo>


# モジュールのインスタンスメソッドの UnboundMethod の場合
module Foo
def foo
"foo"
end
end

# UnboundMethod `m' を生成
p
m = Foo.instance_method(:foo) # => #<UnboundMethod: Foo#f...

UnboundMethod#arity -> Integer (21044.0)

メソッドが受け付ける引数の数を返します。

...][ruby]{
class
C
def one; end
def two(a); end
def three(*a); end
def four(a, b); end
def five(a, b, *c); end
def six(a, b, *c, &d); end
end

p
C.instance_method(:one).arity #=> 0
p
C.instance_method(:two).arity #=> 1
p
C.instance_method(:three).arity #=> -1
p
C.instance_...
...method(:four).arity #=> 2
p
C.instance_method(:five).arity #=> -3
p
C.instance_method(:six).arity #=> -3


String.instance_method(:size).arity #=> 0
String.instance_method(:replace).arity #=> 1
String.instance_method(:squeeze).arity #=> -1
String.instance_method(:count).arity...

Method#inspect -> String (6180.0)

self を読みやすい文字列として返します。

...を返します。

#<Method: klass1(klass2)#method> (形式1)

klass1 は、Method#inspect では、レシーバのクラス名、
UnboundMethod
#inspect では、UnboundMethod オブジェクトの生成
元となったクラス/モジュール名です。

klass2 は、実際に...
...メソッド名を表します。

//emlist[例][ruby]{
module Foo
def foo
"foo"
end
end
class
Bar
include Foo
def bar
end
end

p
Bar.new.method(:foo) # => #<Method: Bar(Foo)#foo>
p
Bar.new.method(:bar) # => #<Method: Bar#bar>
//}

klass1 と klass2 が同じ場合は以...
...j = ""
class
<<obj
def foo
end
end
p
obj.method(:foo) # => #<Method: "".foo>

# クラスメソッド(クラスの特異メソッド)
class
Foo
def Foo.foo
end
end
p
Foo.method(:foo) # => #<Method: Foo.foo>

# スーパークラスのクラスメソッド
class
Bar < Foo
end
p
Bar....
...を返します。

#<Method: klass1(klass2)#method(arg) foo.rb:2> (形式1)

klass1 は、Method#inspect では、レシーバのクラス名、
UnboundMethod
#inspect では、UnboundMethod オブジェクトの生成
元となったクラス/モジュール名です。

klass2 は、実際...
...には付きません。

//emlist[例][ruby]{
module Foo
def foo
"foo"
end
end
class
Bar
include Foo
def bar(a, b)
end
end

p
Bar.new.method(:foo) # => #<Method: Bar(Foo)#foo() test.rb:2>
p
Bar.new.method(:bar) # => #<Method: Bar#bar(a, b) test.rb:8>
//}

klass1 と klas...
...""
class
<<obj
def foo
end
end
p
obj.method(:foo) # => #<Method: "".foo() foo.rb:4>

# クラスメソッド(クラスの特異メソッド)
class
Foo
def Foo.foo
end
end
p
Foo.method(:foo) # => #<Method: Foo.foo() foo.rb:11>

# スーパークラスのクラスメソッド
class
B...

Marshal.#dump(obj, limit = -1) -> String (6126.0)

obj を指定された出力先に再帰的に出力します。

...ないオブジェクトをファイルに書き出そうとすると
例外 TypeError が発生します。
ファイルに書き出せないオブジェクトは以下の通りです。

* 名前のついてない Class/Module オブジェクト。(この場
合は、例外 ArgumentError が...
...のイン
スタンス。Dir, File::Stat, IO とそのサブクラス
File, Socket など。
* MatchData, Data, Method, UnboundMethod,
P
roc, Thread, ThreadGroup, Continuation
のインスタンス。
* 特異メソッドを定義したオブジェクト

また、これらのオブジ...
...を持った Hash は
P
roc を間接的に指していることになります。

//emlist[例][ruby]{
p
Marshal.dump(Hash.new {})
# => -:1:in `dump': cannot dump hash with default proc (TypeError)
//}

マーシャルの動作を任意に定義することもできます。

@param obj ダンプ...

絞り込み条件を変える

Marshal.#dump(obj, port, limit = -1) -> IO (6126.0)

obj を指定された出力先に再帰的に出力します。

...ないオブジェクトをファイルに書き出そうとすると
例外 TypeError が発生します。
ファイルに書き出せないオブジェクトは以下の通りです。

* 名前のついてない Class/Module オブジェクト。(この場
合は、例外 ArgumentError が...
...のイン
スタンス。Dir, File::Stat, IO とそのサブクラス
File, Socket など。
* MatchData, Data, Method, UnboundMethod,
P
roc, Thread, ThreadGroup, Continuation
のインスタンス。
* 特異メソッドを定義したオブジェクト

また、これらのオブジ...
...を持った Hash は
P
roc を間接的に指していることになります。

//emlist[例][ruby]{
p
Marshal.dump(Hash.new {})
# => -:1:in `dump': cannot dump hash with default proc (TypeError)
//}

マーシャルの動作を任意に定義することもできます。

@param obj ダンプ...

Method#super_method -> Method | nil (6120.0)

self 内で super を実行した際に実行されるメソッドを Method オブジェ クトにして返します。

...self 内で super を実行した際に実行されるメソッドを Method オブジェ
クトにして返します。

@see UnboundMethod#super_method

//emlist[例][ruby]{
class
Super
def foo
"superclass method"
end
end

class
Sub < Super
def foo
"subclass method"
end
end

m = S...
...ub.new.method(:foo) # => #<Method: Sub#foo>
m.call # => "subclass method"
m.super_method # => #<Method: Super#foo>
m.super_method.call # => "superclass method"
//}...

Method#to_s -> String (3080.0)

self を読みやすい文字列として返します。

...を返します。

#<Method: klass1(klass2)#method> (形式1)

klass1 は、Method#inspect では、レシーバのクラス名、
UnboundMethod
#inspect では、UnboundMethod オブジェクトの生成
元となったクラス/モジュール名です。

klass2 は、実際に...
...メソッド名を表します。

//emlist[例][ruby]{
module Foo
def foo
"foo"
end
end
class
Bar
include Foo
def bar
end
end

p
Bar.new.method(:foo) # => #<Method: Bar(Foo)#foo>
p
Bar.new.method(:bar) # => #<Method: Bar#bar>
//}

klass1 と klass2 が同じ場合は以...
...j = ""
class
<<obj
def foo
end
end
p
obj.method(:foo) # => #<Method: "".foo>

# クラスメソッド(クラスの特異メソッド)
class
Foo
def Foo.foo
end
end
p
Foo.method(:foo) # => #<Method: Foo.foo>

# スーパークラスのクラスメソッド
class
Bar < Foo
end
p
Bar....
...を返します。

#<Method: klass1(klass2)#method(arg) foo.rb:2> (形式1)

klass1 は、Method#inspect では、レシーバのクラス名、
UnboundMethod
#inspect では、UnboundMethod オブジェクトの生成
元となったクラス/モジュール名です。

klass2 は、実際...
...には付きません。

//emlist[例][ruby]{
module Foo
def foo
"foo"
end
end
class
Bar
include Foo
def bar(a, b)
end
end

p
Bar.new.method(:foo) # => #<Method: Bar(Foo)#foo() test.rb:2>
p
Bar.new.method(:bar) # => #<Method: Bar#bar(a, b) test.rb:8>
//}

klass1 と klas...
...""
class
<<obj
def foo
end
end
p
obj.method(:foo) # => #<Method: "".foo() foo.rb:4>

# クラスメソッド(クラスの特異メソッド)
class
Foo
def Foo.foo
end
end
p
Foo.method(:foo) # => #<Method: Foo.foo() foo.rb:11>

# スーパークラスのクラスメソッド
class
B...

Module#define_method(name) { ... } -> Symbol (20.0)

インスタンスメソッド name を定義します。

...れます。

@param name メソッド名を String または Symbol を指定します。

@param method Proc、Method あるいは UnboundMethod
いずれかのインスタンスを指定します。

@return メソッド名を表す Symbol を返します。

@raise TypeError method...
...に同じクラス、サブクラス、モジュール以外のメソッ
ドを指定した場合に発生します。

//emlist[例][ruby]{
class
Foo
def foo() p :foo end
define_method(:bar, instance_method(:foo))
end
Foo.new.bar # => :foo
//}...

Module#define_method(name, method) -> Symbol (20.0)

インスタンスメソッド name を定義します。

...れます。

@param name メソッド名を String または Symbol を指定します。

@param method Proc、Method あるいは UnboundMethod
いずれかのインスタンスを指定します。

@return メソッド名を表す Symbol を返します。

@raise TypeError method...
...に同じクラス、サブクラス、モジュール以外のメソッ
ドを指定した場合に発生します。

//emlist[例][ruby]{
class
Foo
def foo() p :foo end
define_method(:bar, instance_method(:foo))
end
Foo.new.bar # => :foo
//}...

絞り込み条件を変える

<< 1 2 > >>