Boris Stitnicky Boris Stitnicky - 3 months ago 11
Ruby Question

How to shirk print / puts in Ruby oneliners?

Consider oneliner

$ ruby -e 'puts 1 + 1'


which uses
ruby
as a command-line calculator. I would like to write the expression without
puts
. Is there a switch for it in
ruby
command?

Answer

It is impossible with ruby command line switches, but it’s easily achievable with shell:

⮀ cat /usr/local/bin/rubyoneliner
#!/bin/sh
ruby -e "puts $@"

⮀ rubyoneliner '1 + 1'
2

or with bash/zsh function.