[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

def blah do |x| -- alternate method definition syntax

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


2 Answers

dan.macdaddy+ruby

11/5/2007 5:26:00 AM

0

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

On 11/5/07, Joe Holt <joe07734@gmail.com> wrote:

>
> 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
>
>
>
You don't have to do blah.call, you can do blah[5] which is pretty close :)

dan.macdaddy+ruby

11/5/2007 5:30:00 AM

0

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

Apologies...

Somehow i quoted myself out:

You don't have to do blah.call, you can do blah[5] which is pretty close :)


On 11/5/07, Dan <dan.macdaddy+ruby@gmail.com> wrote:
>
> On 11/5/07, Joe Holt <joe07734@gmail.com> wrote:
>
> >
> > 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
> >
> >
> >
>
>