Re:Show HN: Rb – Turns Ruby into a command line utility
by star-techate on Monday August 13, 2018 @11:47PM
(#17755463)
Command line tools in 10 lines of ruby (using this script):
Command line tools in zero lines of ruby (using ruby):
Bit of a pain as ++ is lacking, as is autovivication. a /bin/sort at the end usually beats `<=>` for terseness.
[ Parent
| on HN ]
Re:Show HN: Rb – Turns Ruby into a command line utility
by shawn on Tuesday August 14, 2018 @12:08AM
(#17755530)
In case it’s helpful, as someone who doesn't know ruby, it's hard to understand. Not too readable. Split.last.ljust I just barely understood (left-justify the last match), but I have no idea what the next part is even trying to accomplish.
It's a cool script though.
Re:Show HN: Rb – Turns Ruby into a command line utility
by star-techate on Tuesday August 14, 2018 @12:14AM
(#17755549)
That's the author's oneliner. I don't know what that code is for either, which is part of I rewrote it in the second set of examples.
It's normal for a oneliner to be somewhat inscrutable though, since they're often extremely dependent on their inputs. Like if it's important to fetch the 3rd, 5th, and 7th column--why? You can't tell without the input.
Re:Show HN: Rb – Turns Ruby into a command line utility
by asicsp on Tuesday August 14, 2018 @02:17AM
(#17755924)
for the 3rd example, not sure why you are manually building the array..
df -h | ruby -e 'puts readlines.drop(1).sort_by { |l| l.split[-2].to_f }'
similarly, the `uniq` example from your other comment could be shortened to printf 'hello\nworld\nhello\n' | ruby -e 'puts readlines.uniq'