Ruby Hello World

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


Ruby is an interpreted language. It is object oriented. The code it requires to run is minimal and therefore, it is fast to write.

Ruby "Hello World"

#!/usr/bin/ruby
# Filename: helloworld.rb
 
puts "Hello World"

In the above code, puts is similar to print in other languages. First line tells the program where is ruby executable installed.

Ruby "Simple Arithmetic" Example

#!/usr/bin/ruby
# Filename: arithmetic.rb
num = 2 *  2
ruby_string_var  = num.to_s
puts "Result after converting number to string = " + ruby_string_var

Note, in the above code a numeric num is converted to string using to_s() method.





Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.