How is the __LINE__ and __FILE__ constants implemented in Ruby? -


it seems __file__ , __line__ constants dynamically updated current file , line numbers under execution, wondering how behaviour implemented in ruby?

i've greped source code there many noises __line__ , __file__ appearance, wonder me point source code , provide clue understand behaviour.

explanation in either rubinis or mri fine.

both __file__ , __line__ replaced literals directly in parser:

case keyword__file__:     return new_str(rb_external_str_new_with_enc(ruby_sourcefile, strlen(ruby_sourcefile),                                                 rb_filesystem_encoding())); case keyword__line__:     return new_lit(int2fix(tokline)); 

in other words, behave if had typed in resulting string or number yourself.

note __line__, doesn't behave how you'd expect.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -