Skip to content

Instantly share code, notes, and snippets.

@mitchty
Created December 7, 2011 03:32
Show Gist options
  • Save mitchty/1441323 to your computer and use it in GitHub Desktop.
Save mitchty/1441323 to your computer and use it in GitHub Desktop.
dumb eval loop with output from the eval
$ cat eval_with_comment.rb
b = binding
input = $stdin.read.split(/\n/)
input.each do |line|
line.gsub(/\s+\#.*$/, %q{})
out = eval line, b
puts "#{line} \# #{out.inspect}"
end
$ cat a.rb | ruby eval_with_comment.rb
%w/a b c d/ # ["a", "b", "c", "d"]
STDOUT.tty? # true
require 'socket' # true
example="example text is example" # "example text is example"
example.gsub(/xamp/, 'unk') # "eunkle text is eunkle"
@mitchty
Copy link
Author

mitchty commented Dec 7, 2011

Just a dumb eval loop, couldn't quickly figure out how to get irb/pry to not print a newline char. Lame little hack.

@mitchty
Copy link
Author

mitchty commented Dec 7, 2011

This also works, sorta:

$ cat a.rb | irb -f --inf-ruby-mode --noinspect --prompt xmp
Switch to non inspect mode.
%w/a b c d/
==>["a", "b", "c", "d"]
STDOUT.tty?
==>true
require 'socket'
==>true
example="example text is example"
==>example text is example
example.gsub(/xamp/, 'unk')
==>eunkle text is eunkle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment