From: "Mehr, Assaph (Assaph)" Date: 2004-04-06T12:19:45+09:00 Subject: Re: line directives > Does ruby support anything like #line directives in C or Perl? or > any other way to dynamically change what ruby thinks is the current > sourcefile and sourceline in its warning and error reporting? What exactly do you need it for? If it's for reporting exceptions, you can manipulate the info returned by Kernel::caller with the third argument of Kernel::raise. E.g.: # define stuff for a nice call stack: irb(main):007:0> def f irb(main):008:1> g irb(main):009:1> end => nil irb(main):014:0> def g irb(main):015:1> raise StandardError irb(main):016:1> end => nil irb(main):017:0> f StandardError: StandardError from (irb):15:in `g' from (irb):8:in `f' from (irb):17 # but if we define g to muck up the caller argument: irb(main):010:0> def g irb(main):011:1> raise StandardError, "", "my_ficticious_script:imaginary_line: Go look here!\n\t" + caller[1] irb(main):012:1> end => nil irb(main):013:0> f StandardError: from my_ficticious_script:imaginary_line: Go look here! (irb):13