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

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -