[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: how to have a default argument

Jos Backus

4/17/2007 5:53:00 PM

On Wed, Apr 18, 2007 at 02:44:23AM +0900, shawn bright wrote:
> hello all,
>
> i have a function that sometimes needs to be passed a variable, but
> sometimes not.
>
> def get_some_records(year)

def get_some_records(year=Time.now.year)

> get records for year
> process them
> return result
> end
>
> the thing is, i already have it written, but i would like to have a default
> like if get_some_records() is called, year would be assumed to be 2007
>
> is there a way i can do this without having to change everywhere it is
> called in my code?
>
> thanks
> sk

--
Jos Backus
jos at catnook.com