Roshan Book

My Tech Notebook

Learning Ruby Part 4–Methods


Methods are something which Objects do.

Defining a Method

class Manish
def talk
puts "Hi, my name is Manish"
end
end

 

Notice the two ends. One end , ends method and other one ends class. Now we have a class Manish having a Method Talk.

 

Calling Method

man=Manish.new
man.talk

Objects are characteristics of Class and Methods are what Classes do.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: