Let Ruby report the correct line numbers. #1

Merged
merged 1 commit into from Aug 22, 2012

Conversation

Projects
None yet
3 participants
Contributor

splattael commented Aug 22, 2012

No description provided.

This pull request passes (merged 6d98cc5 into c2bf1a1).

Owner

ernie commented Aug 22, 2012

I tend to prefer reporting against the class eval and not against the first line evaled.

Contributor

splattael commented Aug 22, 2012

Ok, may be I wasn't clear.

Adding a raise "foo" inside an eval'ed block.

 23     class_eval <<-EVAL, __FILE__, __LINE__
 24       def hash
 25         [#{ivar_or_method_names.join(', ')}].hash
 26         raise "foo"
 27       end
 28     EVAL

Without patch

It gives me the wrong line number 30.

     RuntimeError:
       foo
     # ./lib/equivalence.rb:30:in `hash'
     # ./spec/equivalence/equivalence_spec.rb:54:in `uniq'
     # ./spec/equivalence/equivalence_spec.rb:54:in `block (2 levels) in <top (required)>'

With the patch

It gives me the line number where the raise "foo" happened:

     RuntimeError:
       foo
     # ./lib/equivalence.rb:26:in `hash'
     # ./spec/equivalence/equivalence_spec.rb:54:in `uniq'
     # ./spec/equivalence/equivalence_spec.rb:54:in `block (2 levels) in <top (required)>'

Maybe I misunderstood you!

Owner

ernie commented Aug 22, 2012

Hm. Sure enough. Looks like doing some math against LINE forces it to get evaluated properly, and offsets it to the start of the heredoc as well. Otherwise, the end of the "line" in Ruby's observation doesn't occur until after the heredoc. I'll get it merged. Thanks. :)

ernie added a commit that referenced this pull request Aug 22, 2012

Merge pull request #1 from splattael/eval_line_numbers
Let Ruby report the correct line numbers.

@ernie ernie merged commit f874095 into ernie:master Aug 22, 2012

1 check passed

default The Travis build passed
Details
Contributor

splattael commented Aug 22, 2012

Thank you!

BTW, I like your gem :)

@splattael splattael deleted the splattael:eval_line_numbers branch Mar 8, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment