Proc#source_location & #inspect shows wrong line number when chained
When procs are chained, the line number for each proc is mis-calculated to be the 1st proc's line-number.
class Foo def bar(&blk) pp blk.source_location self end end Foo.new.bar do puts 'b1' end.bar do puts 'b2' end
The 1st & 2nd procs show the same line number, when they shouldn't.
Though i listed the target version as 1.9.2, this behaviour is consistent for all versions of mri.
#1 [ruby-core:41544] Updated by Yasushi ANDO almost 5 years ago
It may not a bug but a specification. A block returns the number of a line in which the block is defined for its "source_location." When you use procs instead of blocks, it returns the values you expected.
1 require 'pp'
2 class Foo
3 def bar(&blk)
4 pp blk.source_location
10 puts 'b1'
12 puts 'b2'
$ ruby procs.rb
#2 Updated by Nobuyoshi Nakada almost 5 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100