ruby - How to run IRB.start in context of current class -
i've been going through pragprog continuous testing ruby, talk invoking irb
in context of current class inspect code manually.
however, quote if invoke irb.start
in class, self predefined, , refers object in when start called isn't true in case.
even simple example like
a = "hello" require 'irb' argv.clear # otherwise script parameters passed irb irb.start
when try access a
variable, obvious
nameerror: undefined local variable or method `a' main:object
it works when change a
global variable
$a = "hello" require 'irb' argv.clear # otherwise script parameters passed irb irb.start
then can access it
irb(main):001:0> $a => 1
is there way around access local , instance variables in current class?
i'd suggest trying in ripl, irb alternative. above example works:
a = 'hello' require 'ripl' ripl.start :binding => binding
note local variables work because passing current binding :binding option.
you possibly same in irb, since it's poorly documented , untested, chances of doing cleanly slim none.
Comments
Post a Comment