Hacker News new | past | comments | ask | show | jobs | submit login

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



Someone 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


OP apparently wants to process an array of lines, not just each line separately.


We need to be using lazy coolections.


So:

  execute(STDIN.each_line, code)
which gives you a lazy enumerator, in place of:

  execute(STDIN.readlines, code)
which gives you an Array.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: