Created
December 7, 2011 03:32
-
-
Save mitchty/1441323 to your computer and use it in GitHub Desktop.
dumb eval loop with output from the eval
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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" |
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
Just a dumb eval loop, couldn't quickly figure out how to get irb/pry to not print a newline char. Lame little hack.