#!/bin/sh # vi: set syntax=ruby: ################################################## # polyglot to use shell to pick correct ruby ################################################## if [ "a" != "a" ]; then printf "" # polyglot 'nop' - we are in ruby =begin else if [ -x "/home/tools/installs/ruby-2.4.0/bin/ruby" ]; then set "/home/tools/installs/ruby-2.4.0/bin/ruby" "$0" "$*" else set "/usr/bin/ruby" "$0" "$*" fi exec $@ fi =end end ## RUBY CODE FOLLOWS...Why it works is an exercise left to the reader. Note that this may confuse some editors that base the syntax off the shebang line, such as emacs, though the second line above will make sure that vi/vim work using modeline magic. For another solution, see RosettaCode
Back to Solutions.