Ruby, pry: Can I add something to the command `pry example.rb` so pry automatically goes interactive when it finishes executing the script?
Not yet, but file an issue and i'll add it :)
__FILE__ returns different value when using binding.pry
Use _file_
instead of __FILE__
. For example, given two files:
# foo.rb
require 'pry'
require './bar'
binding.pry
b = Bar.new
and:
# bar.rb
require 'pry'
class Bar
def initialize
binding.pry
end
end
Run them with ruby foo.rb
:
ruby foo.rb
From: /Users/username/foo.rb @ line 3 :
1: require 'pry'
2: require './bar'
=> 3: binding.pry
4: b = Bar.new
(main):1 ⇒ _file_
=> "/Users/username/foo.rb"
(main):2 ⇒ exit
From: /Users/username/bar.rb @ line 4 Bar#initialize:
3: def initialize
=> 4: binding.pry
5: end
(#<Bar:0x00007fbb6caaff08>):1 ⇒ _file_
=> "/Users/username/bar.rb"
_file_
and any other local variable names can be found in binding.local_variables
.
Related Topics
Problem Running Thinking Sphinx with Rails 2.3.5
Triple Single Quote VS Triple Double Quote in Ruby
Gets.Chomp Without Moving to a New Line
Scraping an Angularjs Application
Require Ruby File Without .Rb Extension
How Is Ruby Tcpsocket Timeout Defined
Using $1, $2, etc. Global Variables Inside Method Definition
Sinatra Helper to Fake a Request
How Would I Go About Converting This Time String to Epoch Time in Ruby
How to Set Correct Ruby Version in Gem Environment
Exec the Cd Command in a Ruby Script
Get Pry to Display Characters Like [äöüßÄÖÜß] (Utf-8 Encoding)? (Possibly Windows-Specific Issue)
Rails Query Timestamp Between Two Hours
Show Markers on Google Maps Dynamically -Rails 3.2
Why Does 'Puts(Nil or 4)' Fail in Ruby
Why Does Date.Yesterday Counts as Date.Today Also