J
Joel VanderWerf
Proc#inspect typically returns a string like:
#<Proc:[email protected]:3>
where the "3" is the first line of the code block in file "file.rb".
It would be easier to extract the entire code block without doing
parsing if Proc#inspect returned a _range_ of lines:
#<Proc:[email protected]:3..5>
It would also be nice to have reader methods to get this information
from the proc:
Proc#file
Proc#line_start
Proc#line_finish
Opinions? Is there something simple I'm missing?
I thought that eval-ing __LINE__ against the proc's binding might give
the last line of the proc's definition, but actually the results are
surprisingly inconsistent:
$ cat t1.rb
pr = proc {
1+1
puts
}
p eval("__LINE__", pr)
$ ruby t1.rb
2
$ cat t2.rb
pr = proc {
x=1+1
puts
}
p eval("__LINE__", pr)
$ ruby t2.rb
4
#<Proc:[email protected]:3>
where the "3" is the first line of the code block in file "file.rb".
It would be easier to extract the entire code block without doing
parsing if Proc#inspect returned a _range_ of lines:
#<Proc:[email protected]:3..5>
It would also be nice to have reader methods to get this information
from the proc:
Proc#file
Proc#line_start
Proc#line_finish
Opinions? Is there something simple I'm missing?
I thought that eval-ing __LINE__ against the proc's binding might give
the last line of the proc's definition, but actually the results are
surprisingly inconsistent:
$ cat t1.rb
pr = proc {
1+1
puts
}
p eval("__LINE__", pr)
$ ruby t1.rb
2
$ cat t2.rb
pr = proc {
x=1+1
puts
}
p eval("__LINE__", pr)
$ ruby t2.rb
4