Sample Ruby code

 

Sample Ruby Code

Here is a sample Ruby code to print "Hello Ruby"

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

   def salute
      puts "Hello #{@name}!"
   end
   
end

# Create a new object
h = Hello.new("Ruby")

# Output "Hello Ruby!"
h.salute

Output − This will produce the following result −

Hello Ruby!

Comments

Popular posts from this blog

Rails 7 Features :: Comparison with Rails 6 and Rails 5