るりまサーチ

最速Rubyリファレンスマニュアル検索!
87件ヒット [1-87件を表示] (0.112秒)
トップページ > クエリ:i[x] > クエリ:class[x] > クラス:Method[x]

別のキーワード

  1. _builtin to_i
  2. fiddle to_i
  3. matrix elements_to_i
  4. csv to_i
  5. matrix i

ライブラリ

キーワード

検索結果

Method#inspect -> String (6231.0)

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

...します。

以下の形式の文字列を返します。

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

klass1 は、Method#inspect では、レシーバのクラス名、
UnboundMethod#inspect では、UnboundMethod オブジェクトの生成
元となったクラス/モジュ...
...モジュール名、
method
は、メソッド名を表します。

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

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

klass...
...が同じ場合は以下の形式になります。
#<Method: klass1#method> (形式2)

特異メソッドに対しては、
#<Method: obj.method> (形式3)
#<Method: klass1(klass2).method> (形式4)
という形式の文字列...
...します。

以下の形式の文字列を返します。

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

klass1 は、Method#inspect では、レシーバのクラス名、
UnboundMethod#inspect では、UnboundMethod オブジェクトの生成
元となったクラス/モジ...
...ール名、
method
は、メソッド名を表します。

arg は引数を表します。
「foo.rb:2」は Method#source_location を表します。
source_location が nil の場合には付きません。

//emlist[例][ruby]{
module Foo
def foo
"foo"
end
end
class
Bar
i
nclude 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 と klass2 が同じ場合は以下の形式になります。
#<Method: klass1#method() foo.rb:2> (形式2)...

Method#arity -> Integer (6107.0)

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

...

//emlist[例][ruby]{
class
C
def u; end
def v(a); end
def w(*a); end
def x(a, b); end
def y(a, b, *c); end
def z(a, b, *c, &d); end
end

c = C.new
p c.method(:u).arity #=> 0
p c.method(:v).arity #=> 1
p c.method(:w).arity #=...
...> -1
p c.method(:x).arity #=> 2
p c.method(:y).arity #=> -3
p c.method(:z).arity #=> -3

s = "xyz"
s.method(:size).arity #=> 0
s.method(:replace).arity #=> 1
s.method(:squeeze).arity #=> -1
s.method(:count).arity #=> -1
//}...

Method#original_name -> Symbol (6107.0)

オリジナルのメソッド名を返します。

...オリジナルのメソッド名を返します。

//emlist[例][ruby]{
class
C
def foo; end
alias bar foo
end
C.new.method(:bar).original_name # => :foo
//}

@see UnboundMethod#original_name...

Method#receiver -> object (6107.0)

このメソッドオブジェクトのレシーバを返します。

...のメソッドオブジェクトのレシーバを返します。

//emlist[例][ruby]{
class
Foo
def foo(arg)
"foo called with arg #{arg}"
end
end

m = Foo.new.method(:foo) # => #<Method: Foo#foo>
m.receiver # => #<Foo:0x007fb39203eb78>
m.receiver.foo(1) # => "foo called with arg 1"
//}...

Method#source_location -> [String, Integer] | nil (6107.0)

ソースコードのファイル名と行番号を配列で返します。

...合は nil を返します。

@see Proc#source_location

//emlist[例][ruby]{
# ------- /tmp/foo.rb ---------
class
Foo
def foo; end
end
# ----- end of /tmp/foo.rb ----

require '/tmp/foo'

m = Foo.new.method(:foo) # => #<Method: Foo#foo>
m.source_location # => ["/tmp/foo.rb", 2]

method
(:puts).s...
...ource_location # => nil
//}...

絞り込み条件を変える

Method#unbind -> UnboundMethod (6107.0)

self のレシーバとの関連を取り除いた UnboundMethod オブ ジェクトを生成して返します。

...いた UnboundMethod オブ
ジェクトを生成して返します。

//emlist[例][ruby]{
class
Foo
def foo
"foo"
end
end

m = Foo.new.method(:foo) # => #<Method: Foo#foo>
unbound_method = m.unbind # => #<UnboundMethod: Foo#foo>
unbound_method.bind(Foo.new) # => #<Method: Foo#foo>
//}...

Method#to_s -> String (3131.0)

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

...します。

以下の形式の文字列を返します。

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

klass1 は、Method#inspect では、レシーバのクラス名、
UnboundMethod#inspect では、UnboundMethod オブジェクトの生成
元となったクラス/モジュ...
...モジュール名、
method
は、メソッド名を表します。

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

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

klass...
...が同じ場合は以下の形式になります。
#<Method: klass1#method> (形式2)

特異メソッドに対しては、
#<Method: obj.method> (形式3)
#<Method: klass1(klass2).method> (形式4)
という形式の文字列...
...します。

以下の形式の文字列を返します。

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

klass1 は、Method#inspect では、レシーバのクラス名、
UnboundMethod#inspect では、UnboundMethod オブジェクトの生成
元となったクラス/モジ...
...ール名、
method
は、メソッド名を表します。

arg は引数を表します。
「foo.rb:2」は Method#source_location を表します。
source_location が nil の場合には付きません。

//emlist[例][ruby]{
module Foo
def foo
"foo"
end
end
class
Bar
i
nclude 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 と klass2 が同じ場合は以下の形式になります。
#<Method: klass1#method() foo.rb:2> (形式2)...

Method#super_method -> Method | nil (113.0)

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

... 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 = Sub.new.method(:foo) # => #<Method: Sub#foo>
m.call # => "subclass m...
...ethod"
m.super_method # => #<Method: Super#foo>
m.super_method.call # => "superclass method"
//}...