Gary Thomas
5/30/2007 6:25:00 PM
> -----Original Message-----
> From: aidy.lewis@googlemail.com [mailto:aidy.lewis@googlemail.com]
> Sent: Thursday, 31 May 2007 5:35 a.m.
> To: ruby-talk ML
> Subject: Re: using hash for method parameters
>
>
> On 30 May, 18:17, Roseanne Zhang <rosea...@javaranch.com> wrote:
>
> > Try the following:
> >
> > class Login
> >
> > def with(username, password)
> > @username = username
> > @password = password
> > end
> > end
> >
> >
> > login = Login.new
> > login.with("abc", "def")
> > p login
> >
> Thanks for the post, but I am trying to explicitly name the parameters
> in the call, by attempting to use symbols and a hash, to make things a
> little more readable.
>
> So, I would like my call to contain something like this:
>
> login = Login.new
> login.with(:username => 'aidy', :password => 'aidy1')
>
> cheers
>
> aidy
>
You could use something like:
class Login
def with(params)
@username = params[:username]
@password = params[:password]
end
end
login = Login.new
login.with({:username => 'aidy', :password => 'aidy1'})
Haven't tested this but it gives the general idea.
Gary Thomas