2008年09月14日
Rubinius は出来る子!という話
以下の記事を読みました。
それはさすがにどうだろう、と思うわけですが、でも我々には Rubinius という素晴らしい武器があるではないですか!
class Foo Map = { 'key1' => lambda { |bar| puts bar p MethodContext.current.sender.sender.receiver } } def baz(key, bar) Map[key].call(bar) end end foo = Foo.new foo.baz('key1', foo.object_id.to_s) #=> 9 #=> #<Foo:0x9>
てなわけで、出来なくはありません。でもこういうのを使うと世間様に怒られそうな気がします。
追記
id:miura1729 さんの Binding.of_caller はとってもタメになるので是非読みましょう。CRuby でもこんな方法で出来るんですね、ありがとうございました!
CRubyも出来る子!という話 - miura1729の日記
Binding.of_caller のことを今まで知らなかったのですが(出自は Rails なのかな、それとももっと前からあるのかな?)、おお、なんと見事な set_trace_func でしょうか。return してから line に入ったタイミングで binding を取得するわけですね。賢いなぁ。set_trace_func は注目したことがなかったのでなにか楽しい活用方法を考えてみたいと思いました。
トラックバック - http://d.hatena.ne.jp/keita_yamaguchi/20080914/1221328049
リンク元
- 15 http://reader.livedoor.com/reader/
- 12 http://d.hatena.ne.jp/miura1729/
- 10 http://webcache.googleusercontent.com/search?q=cache:GA-HxGsf82YJ:d.hatena.ne.jp/keita_yamaguchi/20080912/1221222787+has+no+member+named+窶惑ilename&cd=1&hl=ja&ct=clnk&gl=jp&lr=lang_ja&client=firefox-a
- 8 http://d.hatena.ne.jp/miura1729/20080914/1221369931
- 8 http://d.hatena.ne.jp/repeatedly/20080914/1221396425
- 6 http://d.hatena.ne.jp/repeatedly/
- 6 http://twitter.com/
- 5 http://74.125.153.132/search?q=cache:GA-HxGsf82YJ:d.hatena.ne.jp/keita_yamaguchi/20080912/1221222787+エラー without+a+valid+PTR&cd=1&hl=ja&ct=clnk&gl=jp&lr=lang_ja
- 5 http://www.google.co.jp/search?q=OSC+島根&lr=lang_ja&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:ja:official&client=firefox-a
- 4 http://fastladder.com/reader/

