The ratchet gets an attach message. What needs to be attached? The
method arguments: the captive_monkey and the captive_star. We are
given back a starmonkey, which we have decided to hang on to.
Ruby is a dynamic language – nothing is static in the sense of Java
or C++. Further, every expression evaluates to an object, so
ratchet.attach(captive_monkey, captive_star) returns an object (of
some kind — _why doesn’t tell us what kind and it doesn’t matter
much – class is not the big deal in Ruby that it is in languages
with static typing of variables). ratchet is an object of a class
that has an attach method which knows how, given a monkey and a star.
to produce something _why calls a starmonkey.
starmonkey is an object, yes? Of what class?
The variable starmonkey is bound to the object returned by the
expression on the right-hand side of the assignment – it can be
used, for some execution extent, to refer to that object.
The ratchet gets an attach message. What needs to be attached? The
method arguments: the captive_monkey and the captive_star. We are
given back a starmonkey, which we have decided to hang on to.
He doesn’t say, and I don’t think that is the point of the example. The
example shows you how to call a method. Whether it’s a static/class
method or a regular method is irrelevant. However, on the previous page
there is a clue:
Class methods
Like the methods described above (also called instance methods), class
methods are usually attached after variables and constants. Rather than
a dot, a double colon is used.
Door::new( :oak )
Since 1) ratchet does not start with a capital letter, and 2) there is
no scope resolution operator(: after ratchet, you can draw your own
conclusions.
ratchet is an object or a static class?
Once again, that’s irrelevant to the example. But since ratchet doesn’t
start with a capital letter…
starmonkey is an object, yes?
Yes, but everything is an object in ruby, so that doesn’t say much about
starmonkey.
On Sun, 21 Oct 2007 13:26:56 +0900, 7stud – wrote:
Like the methods described above (also called instance methods), class
methods are usually attached after variables and constants. Rather than
a dot, a double colon is used.
Door::new( :oak )
Ah, yes thanks. Also, that Ruby doesn’t have static typing I find
confusing – but will continue on!
Thanks again,
Thufir
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.