Can anyone help reduce my confusion? I think I understand the “how” of
proc blocks, but I still don’t get the “why,” particularly with a
dynamically passed block of code, like in the following sample:
def dummyMethod(&dynamicBlock)
dynamicBlock.call
end
dummyMethod {
puts 'This is line 1 of custom block code’
puts ‘This is line 2 of custom block code’
}
From what I’ve read, the proc block feature isn’t found in many
languages, and makes Ruby (and others like Lisp) much more flexible
and powerful. However, I don’t quite grasp why. Is the benefit that
you don’t need to modify “dummyMethod” at all, but rather just modify
the code within the block? And if this is the case, why is that
better? After all, if you have to make code changes, you still have to
change it somewhere, regardless of whether you’re changing it in
"dummyMethod" or in the code block. I don’t see the benefit of passing
blocks of code around instead of just including that code in the
method you’re calling.
I’m coming at this from a Visual Basic background, so I’m sure I’m a
bit like a Neanderthal being shown a power drill and wondering why
it’s any better than my rock tool. I get the feeling that proc blocks
can do great things, but I just don’t see why. And is there any
benefit to passing a dynamic block as shown above as opposed to
creating a new Proc object as shown here?
def dummyMethod(passedProcBlock)
passedProcBlock.call
end
newProcBlock = Proc.new {
puts 'This is line 1 of custom block code’
puts ‘This is line 2 of custom block code’
}
dummyMethod (newProcBlock)
Also, on a completely unrelated note, does anyone know how can I
change my Google Groups email display address to include the words
"REMOVE4SPAM" or some similar word? I tried changing it but Google
sends an email to the address to verify the change.
Thanks for everyone’s help! It’s very exciting being part of this
community, which seems to be on the cutting edge of the programming
future.