Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the ruby equivalent of python -i?

Tags:

python

ruby

python -i will execute a script then provide an interactive prompt which still has access to the variables declared in the script. Does ruby have an equivalent option? I've tried require but it seems the variables are no longer in scope after using it. E.g.,:

Steven$ cat simple.rb 
s = "hello"

Steven$ irb
irb(main):001:0> require_relative('simple')
=> true
irb(main):002:0> puts s
NameError: undefined local variable or method `s' for main:Object
    from (irb):2
    from /usr/bin/irb:12:in `<main>'
irb(main):003:0> 
like image 359
Steven Avatar asked Jun 08 '26 13:06

Steven


1 Answers

You could use pry:

simple.rb:

s = "hello"
binding.pry

in the console:

$ pry simple.rb 
[1] pry(main)> puts s
hello
=> nil
[2] pry(main)> 
like image 129
August Avatar answered Jun 11 '26 06:06

August