objects or variables?

T

Thufir

I'm going by "Why's (poignant) Guide to Ruby":

starmonkey = ratchet.attach( captive_monkey, captive_star )

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.

<http://poignantguide.net/ruby/chapter-4.html>

ratchet.attach() is a static method?

ratchet is an object or a static class?

starmonkey is an object, yes? Of what class?




thank you,

Thufir
 
M

Morton Goldberg

I'm going by "Why's (poignant) Guide to Ruby":

starmonkey = ratchet.attach( captive_monkey, captive_star )

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.

<http://poignantguide.net/ruby/chapter-4.html>

ratchet.attach() is a static method?

ratchet is an object or a static class?

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.

Regards, Morton
 
7

7stud --

Thufir said:
I'm going by "Why's (poignant) Guide to Ruby":

starmonkey = ratchet.attach( captive_monkey, captive_star )

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.

<http://poignantguide.net/ruby/chapter-4.html>

ratchet.attach() is a static method?

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( :eek:ak )
----

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.

Of what class?

The Starfish class.
 
T

Thufir

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( :eek:ak )
----


Ah, yes thanks. Also, that Ruby doesn't have static typing I find
confusing -- but will continue on!



Thanks again,

Thufir
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,269
Messages
2,571,338
Members
48,025
Latest member
Rigor4

Latest Threads

Top