[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: one-line function definitions

SonOfLilit

6/18/2007 5:31:00 PM

Transliterated (counting cultural differences), it owuld become:

def antology_title (data, prefix); get_field(data, prefix,
'ANTHOLOGY-TITLE'); end

But more importantly, it probably wouldn't exist, since ruby culture
sees explicit getters/setters as repeating yourself and finds
meta-solutions, a-la attr_accessor or def_delegator.

Aur

On 6/18/07, Mike Steiner <mikejaysteiner@gmail.com> wrote:
> I'm converting some code from Python to Ruby and can't figure out the syntax
> for one-line function definitions in Ruby. For example, what would this line
> be in Ruby?
>
> def GetAnthologyTitle ( data , prefix ): return GetField ( data , prefix ,
> 'ANTHOLOGY-TITLE' )
>
> Mike Steiner
>

1 Answer

Gavin Kistner

6/18/2007 5:38:00 PM

0

On 6/18/07, Mike Steiner <mikejaystei...@gmail.com> wrote:
> I'm converting some code from Python to Ruby and can't figure out the syntax
> for one-line function definitions in Ruby. For example, what would this line
> be in Ruby?
>
> def GetAnthologyTitle ( data , prefix ): return GetField ( data , prefix ,
> 'ANTHOLOGY-TITLE' )

def foo(x) x*x end
def bar(x) x-102 end
def jim(x) y=foo(x); bar(y) end
p jim(12)
#=> 42