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>
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)>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With