Patrick Dwyer

Ruby

Programming examples in Ruby

Echo :: Ruby

in News, Comparative Programming, Ruby by patrick

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