Show HN: Rb – Turns Ruby into a command line utility
31–40 of 79 posts
Re: Show HN: Rb – Turns Ruby into a command line utility
#32Re: Show HN: Rb – Turns Ruby into a command line utility
#33Earlier quoted context omitted.
It's using Ruby to replace Awk, the way Perl once tried to.
Why the hell would anybody want to replace AWK? It’s super fast, extremely light on resources, doesn’t have any dependencies, does auto memory management and type inference, and is extremely powerful for large dataset processing, not to mention easy to learn and program.
I think that's relative and it certainly hasn't been my experience. If I program in Ruby, Node, Python, etc for 8 hours of every day, it makes sense that I would reach for that over a command line tool with a syntax that looks a bit arcane. The best tool for the job sometimes is the tool you know best.
Re: Show HN: Rb – Turns Ruby into a command line utility
#34$ docker ps | rb drop 1 | rb -l split[1] $ docker ps | perl -anE 'say $F[1] if $.>1' perl solved this problem a long time ago, people
Look again at your code. I'm not 100% sure what the Ruby version does, but once I do figure out the exact semantics of drop and split, it's going to be waaaaaaaaaaaaaaaaay easier to remember, understand and modify the Ruby version than the Perl one.
Your post comes off as something from reddit's /r/nottheonion, you're just making the case against Perl for Perl-haters :)
Re: Show HN: Rb – Turns Ruby into a command line utility
#35What does this have over the default ruby? cat your-file.txt | ruby -ne '$_.your_ruby_stuff' Just syntactic sugar? (it does look cleaner!)
Re: Show HN: Rb – Turns Ruby into a command line utility
#36The 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
Re: Show HN: Rb – Turns Ruby into a command line utility
#37Earlier quoted context omitted.
Why the hell would anybody want to replace AWK? It’s super fast, extremely light on resources, doesn’t have any dependencies, does auto memory management and type inference, and is extremely powerful for large dataset processing, not to mention easy to learn and program.
> easy to learn and program I think that's relative and it certainly hasn't been my experience. If I program in Ruby, Node, Python, etc for 8 hours of every day, it makes sense that I would reach for that over a command line tool with a syntax that looks a bit arcane. The best tool for the job sometimes is the tool you know best.
That's like hammering in screws because you know your hammer and screwdrivers seem arcane to you.
For ad-hoc stuff `ruby -e` is more than enough, and if you want to write a program once and use it a lot, it's worth investing the time in doing it the way it works best, which in this case, would be a (fast) language like awk that makes it easier to process line-by-line instead of reading until EOF and making the rest of the pipeline wait.
Re: Show HN: Rb – Turns Ruby into a command line utility
#38- It's a bit unintiuitive because you don't really know what strings to escape on the bash command line. In the example, some are escaped and others aren't.
- In the end I think this could be achieved with a simple bash function:
$ rb() { ruby -lane "print \$_.instance_eval(\"$@\")"; }
$ echo hello | rb capitalize
$ HelloRe: Show HN: Rb – Turns Ruby into a command line utility
#39The 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