Web Based

Seeing Is Believing

Display what each line evaluates to

There is a gem called rcodetools which comes with a binary named xmpfilter. With xmpfilter, you place a magic comment # => to the right of a line of Ruby code, and it will evalute the code, capture the result, and place it after the magic comment. Seeing Is Believing does this, except that you do not have ot place the magic comment, and it does it for every line of code.

My mentor at 8th Light asked me to make this for him, because he wanted to hook it into KidsRuby's editor so that the kids could get better feedback. We would create a second pane in their editor and display the results of the line of code in the other pane.

As such, the project is structured as a library that will give you a data structure containing the results. And then to mimick the xmpfilter behaviour, there is a binary which reads in your source code, hands it to the library, and then interpolates the results back into the source document.

For example, given the file code.rb:

['abc', 'def', 'ghi'].each do |i|

def second_letter(string)

second_letter "abc"
second_letter "def"
second_letter "ghi"

When we run seeing_is_believing code.rb it outputs

['abc', 'def', 'ghi'].each do |i|
  i.reverse                        # => "cba", "fed", "ihg"
end                                # => ["abc", "def", "ghi"]

def second_letter(string)
  string[1]                # => "b", "e", "h"
end                        # => nil

second_letter "abc"  # => "b"
second_letter "def"  # => "e"
second_letter "ghi"  # => "h"

I've integrated it with TextMate, SublimeText, and Emacs.

Code is on github.