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-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: how to have a default argument
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password