Fixnum.methods.sort
=> [:!, :!=, :!~, :<, :<=, :<=>, ..., :trust, :untaint, :untrust, :untrusted?]
Why doesn't it display :*
, :/
, :+
, :-
, :%
(or :"*"
, ":/"
, etc.) as methods?
I see that they are considered methods.
Fixnum.methods.sort
=> [:!, :!=, :!~, :<, :<=, :<=>, ..., :trust, :untaint, :untrust, :untrusted?]
Why doesn't it display :*
, :/
, :+
, :-
, :%
(or :"*"
, ":/"
, etc.) as methods?
I see that they are considered methods.
Fixnum
is an instance of Class
. Class
doesn't define a *
instance method (what would that even do), nor do Class
's ancestors (Module
, Object
, Kernel
, BasicObject
).
Now, 1
on the other hand is an instance of Fixnum
, and since Fixnum
defines a *
instance method, that instance method shows up when you ask 1
about its methods:
1.methods.sort
# => [:!, :!=, :!~, :%, :&, :*, :**, :+, :+@, :-, :-@, :/, :<, :<<, :<=, … ]
You can see that Fixnum
defines an instance method named *
:
Fixnum.instance_methods.sort
# => [:!, :!=, :!~, :%, :&, :*, :**, :+, :+@, :-, :-@, :/, :<, :<<, :<=, … ]