joe07734
11/5/2007 5:07:00 AM
Hi all,
This came up in a discussion about Ruby with a friend who is learning...
Why aren't method definitions more like blocks? Perhaps it's easier to
explain with some examples. Consider the method blah:
def blah(x)
...
end
And this proc:
lambda do |x|
...
end
Friend wondered why a method definition couldn't be like this:
def blah do |x|
...
end
And I didn't have a good answer, except that "it just is." Maybe I
could have gone into the semantic difference between methods and
lambda procs, but does semantic difference necessitate syntactic
difference?
I tried to simulate this like so:
blah = lambda do |x|
...
end
Which I realize is going down a different path, but still. Now I wish
I could do this:
blah(5)
But I can't. I have to blah.call.
I'm not complaining at all. This isn't bait. It's just me loving Ruby
and wondering aloud. Any opinions?
Joe