Warning: Creating default object from empty value in /home/patricknevindwyer/digilutionary.com/wp-includes/functions.php on line 292
digilutionary.com
Patrick Dwyer

Echo :: Ruby

in News, Comparative Programming, Ruby by patrick


Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/patricknevindwyer/digilutionary.com/wp-includes/functions-formatting.php on line 76

This program is part of the Comparative Programming :: Echo set of examples.

As one of the languages that has an explicit means of joining sets of strings together, the Ruby example is about as short as it gets for an echo program. The predefined array ARGV holds all of our command line arguments, and this object has a join method, to which we can pass any string which will be used to concatenate all of our arguments together. Paired with the puts command, this prints out our arguments, properly spaced and with a newline, all in a single line of code.

Ruby
#!/usr/bin/ruby

puts ARGV.join(" ")

Program Source: echo.rb

Running the example

From the command line:

ruby echo.rb Hello World