M
Mike Stephens
I'm just working through Ruby Visual Quickstart Guide by Larry Ullman,
which is quite an enjoyable book (so far). In it he has this :
"Methods defined outside of any class ... are automatically defined as
part of the Object class. Because every class automatically inherits
from the Object class, these methods are therefore inherited by every
class."
When I tried this, it didn't work (ie write some methods and then
declare a class and try and use those methods on new members of that
class) . Ruby issues an error message - "private error
called...(nomethoderror)".
I lodged a question on Larry's web site, and to his credit he replied in
due course. He said "I'm sorry: what I wrote probably isn't clear there.
Every object inherits the methods in the original Object, but they don't
inherit methods created in situations like this. Sorry for the
confusion!"
It raises an interesting question. When you write methods outside of a
specific class block, you are in the envelope of some top level class,
so why aren't these methods added?
which is quite an enjoyable book (so far). In it he has this :
"Methods defined outside of any class ... are automatically defined as
part of the Object class. Because every class automatically inherits
from the Object class, these methods are therefore inherited by every
class."
When I tried this, it didn't work (ie write some methods and then
declare a class and try and use those methods on new members of that
class) . Ruby issues an error message - "private error
called...(nomethoderror)".
I lodged a question on Larry's web site, and to his credit he replied in
due course. He said "I'm sorry: what I wrote probably isn't clear there.
Every object inherits the methods in the original Object, but they don't
inherit methods created in situations like this. Sorry for the
confusion!"
It raises an interesting question. When you write methods outside of a
specific class block, you are in the envelope of some top level class,
so why aren't these methods added?