2 ms·
Warning: opionion from someone who primarily used python a long time ago Ruby's design is a lot more consistent/predictable/ergonomic than python. the ruby sta
by hxegon 6y ago
Warning: opionion from someone who primarily used python a long time ago
Ruby's design is a lot more consistent/predictable/ergonomic than python. the ruby standard library is honestly amazing (see: https://ruby-doc.org/core-2.7.2/Enumerable.html https://ruby-doc.org/core-2.7.2/Enumerable.html)
Everything is an object, methods take blocks where that makes sense. stuff just feels well thought out and generally when I learn something new about ruby I think 'wow that makes sense' and not 'why would you do it like that'.
There also seems to be much much less churn from a tooling perspective. Learn how gems/bundler works and you're set.
Also, ruby can be a (in my experience) superior replacement for awk.
Brief example, -n is loop over current line as $_, -l is clean up line endings
cat .zsh_history | ruby -nle 'BEGIN{$x=[]}; $x << $_.encode("UTF-8", invalid: :replace, replace: ""); END{$x.sort_by{ _1.count("|") }}'
I was trying to find some longer pipelines from my command history. encode is stripping out a bunch of invalid utf-8, otherwise it would have just been $x<<$_
or, pick a random line from stdin:
ls | ruby -e 'puts ARGF.to_a.sample'