From: Andrew Timberlake Date: 2008-01-08T21:39:56+09:00 Subject: Re: Defining a function inside a function. Whats this feature ? How to use inside a class ? Sur Two things come to mind, are you wanting class methods or instance methods? With the first one, class methods, you don't have to create an instance of Person (I don't think this is what you want) and you simply call the methods directly from the class With the second, instance methods, you need to create an instance of the Person using Person.new and then call the methods on the object. #Class methods: class Person def Person.author p "I am author" end def Person.reader p "I am reader" end end Person.author # -> I am author Person.reader # -> I am reader #Instance methods: class Person def author p "I am author" end def reader p "I am reader" end end person = Person.new person.author # -> I am author person.reader # -> I am reader Andrew Timberlake andrew@andrewtimberlake.com 082 415 8283 skype: andrewtimberlake "I have never let my schooling interfere with my education." --Mark Twain -----Original Message----- From: Sur [mailto:sur.max@gmail.com] Sent: 08 January 2008 02:16 PM To: ruby-talk ML Subject: Defining a function inside a function. Whats this feature ? How to use inside a class ? Hi Everyone, I am not sure if I have seen it being used earlier or probably I don't know how to use it. when I define function(s) inside a function within the main object, it works... def person def author p "I am author" end def reader p "I am reader" end end Now, if I call person.author # => I am author person.reader # => I am reader And it works fine with any hierarchy. The same thing doesn't seem to work inside a class. Any explanation ? Thanks! -- sur "is a String object" is a String object hacking over objects http://expressica.com !DSPAM:3,47836aab145829463747748!