Skip to content

Latest commit

 

History

History
54 lines (41 loc) · 1.96 KB

README.md

File metadata and controls

54 lines (41 loc) · 1.96 KB

RubyEval

Evaluate the current file in Ruby and replace each instance of # => with that lines resulting output.

Installation

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).

Usage

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.

Example

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)

Credits

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.