Pickaxe Question

C

Chris Gehlker

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.
 
C

Chris Gehlker

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)
 

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

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top