るりまサーチ (Ruby 2.1.0)

最速Rubyリファレンスマニュアル検索!
2件ヒット [1-2件を表示] (0.059秒)
トップページ > ライブラリ:ビルトイン[x] > バージョン:2.1.0[x] > クエリ:@[x] > クエリ:|[x] > 種類:クラス[x]

別のキーワード

  1. _builtin |
  2. set |
  3. ipaddr |
  4. array |
  5. integer |

キーワード

検索結果

Thread::Backtrace::Location (100.0)

Ruby のフレームを表すクラスです。

...例1の実行結果:

caller_locations.rb:2:in `a'
caller_locations.rb:5:in `b'
caller_locations.rb:8:in `c'

//emlist[例2][ruby]{
# foo.rb
class
Foo
attr_accessor :locations
def initialize(skip)
@locations = caller_locations(skip)
end
end

Foo.new(0..2).locations.map do |call|
p...

Method (46.0)

Object#method によりオブジェクト化され たメソッドオブジェクトのクラスです。

...、Method は大規模コードに向くと言えます。


既存のメソッドを Method オブジェクト化する。

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

m = Foo.new.method(:foo)

p m # => #<Method: Foo#foo>
p m.call(1) # =...
...cc>
p pr.call(1) # => "proc called with arg 1"
//}

Method オブジェクトが有用なのは以下のような場合。

//emlist[例][ruby]{
class
Foo
def foo() "foo" end
def bar() "bar" end
def baz() "baz" end
end

obj = Foo.new

# 任意のキーとメソッドの関係をハッシュ...
...(Method オブジェクトはレシーバを保持する)必
要がないなら Object#public_sendを使う方法も有用。

//emlist[例][ruby]{
class
Foo
def foo() "foo" end
def bar() "bar" end
def baz() "baz" end
end

# 任意のキーとメソッド(の名前)の関係をハッシュに...