[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

David Mullet

4/17/2007 5:57:00 PM

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

Assign the default value to your argument:

def get_some_records(year=2007)
...
end

Then, if no argument is provided when calling your method, it will
default to 2007.

David
http://rubyonwindows.bl...

--
Posted via http://www.ruby-....