« Return to Thread: Defining a function inside a function. Whats this feature ? How to use inside a class ?

Defining a function inside a function. Whats this feature ? How to use inside a class ?

by sur max :: Rate this Message:

Reply to Author | View in Thread

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

 « Return to Thread: Defining a function inside a function. Whats this feature ? How to use inside a class ?