--cNdxnHkX5QqsyA0e
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On 2007-05-31 02:35:08 +0900 (Thu, May), aidy.lewis / googlemail.com wrote:
> 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')
> 

You can use something like this:

def with params = {}
  params.each do |key,value|
    m = "#{key}="
    self.send(m, value) if self.respond_to?(m)
  end
end

but you should build-in additional checks which will filter out possibly
unsafe assignments, which you would not want here.

Another thing, you may want to call it 'initialize', to be able to use:

login = Login.new :username => 'username', :password => 'pass'

BTW this is similiar to how ActiveRecord works.

-- 
No virus found in this outgoing message.
Checked by 'grep -i virus $MESSAGE'
Trust me.

Tdy przebiegli, żaden z nich kroków nie szczdzi
mny ten, co ucieka, mniejszy, co pdzi.
                                -- Homer, Iliada.

Ceterum censeo Internet Explorer esse delendam.

I have tried to Google this question, but Google said:
"Application error, Rails application failed to start properly"

()  The ASCII Ribbon Campaign - against HTML Email,
/\  vCards, and proprietary formats.

--cNdxnHkX5QqsyA0e
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7-ecc0.1.6 (GNU/Linux)

iD8DBQFGXqdJsnU0scoWZKARAjSRAJkBd6Z2o8icVk/vX6tqcX2k4r7GcgCeMJue
QFH0+qbZtTiREJODbC3Ox800
-----END PGP SIGNATURE-----

--cNdxnHkX5QqsyA0e--