Introduction to Ruby

Ruby is an interpreted, object-oriented programming language. It is open source programming language with a focus on simplicity. Ruby is simple in appearance and It has an elegant syntax that is natural to read and easy to write. Everything is an object in Ruby. Every bit of information and code can be given their own properties and actions. In Ruby Object-oriented programming calls properties by the name instance variables and actions are known as methods. Ruby is a flexible language and it allows users to freely alter its parts.

Features of Ruby

  • Ruby has exception handling features
  • Ruby features a true mark-and-sweep garbage collector for all Ruby objects.
  • Writing C extensions in Ruby is easier than in Perl or Python. A SWIG interface is also available.
  • If an OS allows Ruby can load extension libraries dynamically.
  • OS independent threading
  • Ruby is highly portable

Ruby Programming Code

# The Greeter class
class Greeter
  def initialize(name)
    @name = name.capitalize
  end

  def salute
    puts "Hello #{@name}!"
  end
end
# Create a new object
g = Greeter.new("world")
# Output "Hello World!"
g.salute