what is called Methods in Ruby?

As name itself tells definition, a method is so called because it provides a method (that is, ‘a way’) for an object to respond to messages. In OOP terminology, you send a message to an object by asking it to do something. So let’s imagine that you have an object called robot which has a method called greetfriends. See an example below how you would send it a greetfriends message:

robot. greetfriends

Let’s suppose that the greetfriends method looks like this:

def greetfriends

puts( “Hi Friends Good morning. Welcome to Gyantoday.com” )


When we send robot a greetfriends message it responds with the greetfriends method and display “Hi Friends Good morning. Welcome to Gyantoday.com”.

In Ruby programming a method is declared with the keyword def followed by a method name which should begin with a lowercase letter. See an example below:

def writesomething

puts( “Welcome to Gyantoday.com” )


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.