以下の内容はhttps://tbpgr.hatenablog.com/entry/20141030/1414677727より取得しました。


Ruby | Proc | source_location

概要

Proc#source_location -> [String, Fixnum] | nil

詳細

Procを定義したソースコードのファイル名と行番号を配列で返却。

サンプルコード
require 'tbpgr_utils'

pr1 = Proc.new {}
pr2 = proc {}
lm = lambda {}

bulk_puts_eval binding, <<-EOS
pr1.source_location
pr2.source_location
lm.source_location
EOS

__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

https://rubygems.org/gems/tbpgr_utils
https://github.com/tbpgr/tbpgr_utils

出力

pr1.source_location # => ["proc_source_location.rb", 3]
pr2.source_location # => ["proc_source_location.rb", 4]
lm.source_location  # => ["proc_source_location.rb", 5]



以上の内容はhttps://tbpgr.hatenablog.com/entry/20141030/1414677727より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14