Camp 1 · Schritt 3 von 12
Everything is an object
Numbers have methods, strings have methods, even nil has methods — Ruby's single organizing idea.
Every language has a worldview. Ruby's fits in one sentence: everything is an object, and you talk to objects by sending them messages (methods). Absorb this and the whole language unfolds logically.
Numbers are objects
In most languages, these would be functions applied to numbers. In Ruby
the number itself knows: "7, are you even?" — you ask the object. The
? suffix is a lovely convention: methods ending in ? answer
true/false.
Strings are objects (of course)
Discovering what an object can do
Every object answers .class (what am I?) and .methods (what can I
do?):
Even nil — Ruby's "nothing" — is a real object with a class
(NilClass) and methods (nil.to_s gives ""). No special cases,
no exceptions to memorize: it's objects all the way down.
What does 10.even? return?
Ruby methods ending in ? conventionally…