PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > def blah do |x| -- alternate method definition syntax
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
def blah do |x| -- alternate method definition syntax

Réponse
 
LinkBack Outils de la discussion
Vieux 05/11/2007, 05h07   #1
joe07734@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut def blah do |x| -- alternate method definition syntax

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


  Réponse avec citation
Vieux 05/11/2007, 05h25   #2
dan.macdaddy+ruby@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: def blah do |x| -- alternate method definition syntax

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

  Réponse avec citation
Vieux 05/11/2007, 05h29   #3
dan.macdaddy+ruby@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: def blah do |x| -- alternate method definition syntax

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

>
>


  Réponse avec citation
Vieux 05/11/2007, 14h39   #4
tho_mica_l
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: def blah do |x| -- alternate method definition syntax

> |def blah do |x|
> | ...
> |end


Would it be possible, hypothetically speaking, to make the parser
digest something like:

def bla do(x, y=1, z=2)
...
end

and (maybe instead of or additionally to the experimental -> syntax)

a = arr.map def(x, y=1) ... end

fn = def(x, y=1) ... end

or

a = arr.map do(x, y=1) ... end

fn = do(x, y=1) ... end

I personally am not very fond of curly braces, vertical bars, and
arrows. Maybe it's because I learned Pascal first.


  Réponse avec citation
Vieux 05/11/2007, 15h49   #5
bermonruf@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: def blah do |x| -- alternate method definition syntax

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

I think its almost perfect the way it is, but i would really enjoy blocks
with optional parameters.


--
Bernardo Rufino

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h21.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09839 seconds with 13 queries