Same, but I was doing it so often I made an alias to a script in my dotfiles folder.
ruby_code = ARGV[0]
loop do
line = $stdin.gets()
l = line
break unless line
line.chomp!
final_ruby_code = 'puts "' + ruby_code + '"'
eval(final_ruby_code, binding())
end
#!/usr/bin/env ruby
if ARGV.size != 1
puts "USAGE: ruby-each-line CODE"
exit
end
STDIN.each_line do |line|
line = line.strip
l = line
eval(ARGV.first)
end