Is everything in ruby an object? Does this include Fixnum
s?
views:
91answers:
5Yup.
> Fixnum.is_a?(Object) #=> true
To see the chain of inheritance:
> pp Fixnum.ancestors
[Fixnum,
Integer,
Precision,
Numeric,
Comparable,
Object,
...
Kernel]
=> nil
Yes. Fixnum
is a class, which inherits from Integer
, which inherits from Numeric
, which finally inherits from Object
.
Or, why don't you just ask it? :)
1.is_a? Object # => true
1.class # => Fixnum
Fixnum.is_a? Object # => true
Reading the Ruby info and documentation on the website is a good idea too.
Depends on what you mean by "everything". Fixnum
s are, as the others have demonstrated. Classes also are, as instances of class Class
. Methods, operators and blocks aren't, but can be wrapped by objects (Proc
). Simple assignment is not, and can't. Statements like while
also aren't and can't. Comments obviously also fall in the latter group.
Most things that actually matter, i.e. that you would wish to manipulate, are objects (or can be wrapped in objects).
Ruby doen't have any primitives (like int, char etc in java), so every value (anything that can sit on the right of an assignment statement) is an object. However, control statements, methods, and other features of the language syntax aren't.