irb - Interact with Ruby script after it runs -
i used following in ipython:
run foo
and load file foo.py. every variable defined in file in scope. learning ruby. have hello.rb file have following:
puts "hello" x = 1
when load in irb with
load './hello.rb'
the terminal prints on screen "hello". don't play variable x.
how can this?
thanks.
in ruby cannot access local variables defined in required files. in irb file's local variables out of scope.
there few things can solve this:
define constant:
#hello.rb module sharedconst x = 1 end puts "hello" #in irb puts sharedconst::x # => 1
define instance variables
#hello.rb puts "hello" @x = 1 #in irb @x # => 1
Comments
Post a Comment