3 ms·
The command should process stdin in streaming fashion rather than slurping it all at once: code = ARGV[0] STDIN.each_line do |l| puts l.instance_eval(c
by pulisse 8y ago
The command should process stdin in streaming fashion rather than slurping it all at once:
code = ARGV[0]
STDIN.each_line do |l|
puts l.instance_eval(code)
STDOUT.flush
end
- DarkWiiPlayer 8y agoOP apparently wants to process an array of lines, not just each line separately.
- karmakaze 8y agoWe need to be using lazy coolections.
- dragonwriter 8y agoSo: execute(STDIN.each_line, code) which gives you a lazy enumerator, in place of: execute(STDIN.readlines, code) which gives you an Array.
- redka 8y agoSomeone did a PR[1] with something similar. He also found a way to speed things up by creating a Proc first and feeding it to the eval instead of the string. [1] https://github.com/thisredone/rb/pull/2 https://github.com/thisredone/rb/pull/2