The function(s) defined within a function works fine with any hierarchy only within the main object but gives NoMethodError inside a class.
Lets exemplify it!
Here are the example of both main object and inside a class…
person.author # => I am author
person.reader # => I am reader
person.publisher.authorized # => I am authorized publisher
class Person
def publisher
def authorized
p “I am a authorized publisher”
end
end
end
Person.new.publisher.authorized # => NoMethodError
Its an unexpected behavior in the main object. I don’t know whether its a bug or the feature. But as Matz says it will be removed in the future version of ruby, might be in 2.0