Evaluate the current file in Ruby and replace each instance of # =>
with that lines resulting output.
cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages
git clone https://github.com/kevinthompson/SublimeRubyEval.git RubyEval
You may need to update the path to your Ruby executable. Edit the RubyEval.sublime-settings
file in the ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/RubyEval
folder, and change /usr/local/opt/rbenv/shims/ruby
to whatever the output of running which ruby
in your console is (or to the path of your preferred Ruby executable, if different).
RubyEval will evaluate either your entire file, or the selected region, and will replace any instance of # =>
with its evaluated result. Simply add # =>
to the end of each line that you'd like to display the evaluated result of, then optionally select the region to parse, and execute the ruby_eval
command using your assigned hotkey, or through Sublime Text 2's command pallette.
By default, the ruby_eval
command is bound to super+k, super +e
.
Input (in an unnamed scratch file)
class Person
attr_accessor :name
def initialize(name)
self.name = name
end
end
p = Person.new('Kevin')
p.name # =>
p.age # =>
Output
class Person
attr_accessor :name
def initialize(name)
self.name = name
end
end
p = Person.new('Kevin')
p.name # => "Kevin"
p.age # =>
# ~> -:11: undefined method `age' for #<Person:0x10ecef310 @name="Kevin"> (NoMethodError)
I was inspired to produce this functionality after watcing Avdi Grimm's Ruby Tapas videos.
This version of RubyEval was originally forked from jugyo/SublimeRubyEval, but the code is primarily based off of examples privided in this superuser.com post.