A class is an object. As such it gets a minimum collection of methods.
So when you create the class with
class To_S; def to_s; "to_s "; end; end
the class To_S has the following class methods, which can be viewed by
calling
To_S.methods
[“superclass”, “allocate”, “new”, “public_class_method”,
“public_instance_methods”, “private_method_defined?”, “<=>”,
“class_eval”, “constants”, “==”, “instance_methods”, “===”,
“public_method_defined?”, “module_eval”, “private_instance_methods”,
“included_modules”, “to_s”, “>=”, “<”, “<=”, “method_defined?”,
“const_set”, “ancestors”, “dup”, “>”, “private_class_method”,
“protected_instance_methods”, “include?”, “instance_method”,
“protected_method_defined?”, “class_variables”, “const_defined?”,
“const_get”, “name”, “clone”, “method”, “untaint”, “kind_of?”, “type”,
“instance_variable_get”, “inspect”, “display”, “frozen?”, “taint”,
“send”, “private_methods”, “id”, “=~”, “to_a”, “eql?”, “hash”,
“singleton_methods”, “nil?”, “freeze”, “is_a?”, “class”,
“instance_variable_set”, “methods”, “send”, “instance_eval”,
“extend”, “object_id”, “instance_variables”, “instance_of?”,
“copy_object”, “id”, “protected_methods”, “equal?”, “respond_to?”,
“tainted?”, “public_methods”]
If you call
To_S.new.methods
you get the following instance methods:
[“to_s”, “method”, “untaint”, “kind_of?”, “type”,
“instance_variable_get”, “inspect”, “display”, “frozen?”, “taint”,
“send”, “private_methods”, “id”, “=~”, “to_a”, “eql?”, “dup”,
“hash”, “singleton_methods”, “nil?”, “freeze”, “is_a?”, “class”,
“instance_variable_set”, “methods”, “send”, “instance_eval”,
“extend”, “object_id”, “instance_variables”, “instance_of?”,
“copy_object”, “id”, “protected_methods”, “equal?”, “respond_to?”,
“clone”, “tainted?”, “==”, “public_methods”, “===”]
Regards,
Mark Wilson
···
On Friday, June 13, 2003, at 02:50 AM, you CAN teach an old dog … wrote:
[snip]
class To_S; def to_s; "to_s "; end; end
==> nil
p To_S.new # how come?
==> to_s
puts To_S.new
==> to_s
[snip]