proc Ruby

proc_source.rb


I wrote this a while ago and it works by extracting a proc's origin file  name and line number from its .inspect string and using the source code  (which usually does not have to be read from disc) -- it works with  procs generated in IRB, eval() calls and regular files. It does not work  from ruby -e and stuff like "foo".instance_eval "lambda {}".source  probably doesn't work either.




使

   1  code = proc{puts "Hello World"}
   2  puts code.source #=> puts "Hello World"

これは久々に面白いものを見た気がします。

posted by Png genki on Thu 3 Jul 2008 at 13:43

Comments:

or Preview
Social Bookmarks
  • Delicious
  • B_entry649
  • Clip_16_12_w
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ