[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Pickaxe Question

Chris Gehlker

8/12/2006 7:21:00 PM

On page 53 of the Pickaxe Book there is a little example illustrating
Proc parameters:

songlist = SongList.new
class JukeboxButton < Button
def initialize(label, &action)
super(label)
@action = action
end
def button_pressed
@action.call(self)
end
end
start_button = JukeboxButton.new("Start") { songlist.start }
pause_button = JukeboxButton.new("Pause") { songlist.pause }

If I understand this example correctly, we are supposed to assume
that the
mapping of the instances of JukeboxButton to actual hardware buttons
happens, by magic, when we call the button initializer and pass it
the appropriate string with the super(label) message. But if that's
the case, I don't understand why button_pressed needs to pass self as
an argument to the @action.call message. It seems like the
songlist.start and songlist.pause methods just drop the argument.
--
A young idea is a beautiful and a fragile thing. Attack people, not
ideas.


1 Answer

Chris Gehlker

8/12/2006 8:14:00 PM

0


On Aug 12, 2006, at 12:41 PM, Dave Thomas wrote:

> Yeah, that's true. I don't need to pass it in: it was there from
> the original example, where the block could interrogate the state
> of the button. Sorry it was confusing.

Thanks for the quick reply, Dave. I've been using Ruby off and on for
awhile now but I never felt that i dug in and really understood it.
Hence the picky questions.

---
Neither a man nor a crowd nor a nation can be trusted to act humanely
or to think sanely under the influence of a great fear.

-Bertrand Russell, philosopher, mathematician, author, Nobel laureate
(1872-1970)