Ruby Hello World

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”

# 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

# 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.