Re: How to create "def method(item)= (value)" ?
- From: Phillip Gawlowski <cmdjackryan@xxxxxxxxxxxxxx>
- Date: Wed, 30 Apr 2008 08:10:32 -0500
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
David A. Black wrote:
|> | object.params my_key, 'my value'
|> => @params[:my_key] => 'my value'
|
| "#{key.to_sym}" is always going to produce a string, never a symbol.
*facepalm* Right. String interpolation. Too clever for my own good, is
what I am..
| I'm not sure the OP wants to constrain the keys to be symbols anyway.
Well, given that Rails uses the params hash, with Symbols as keys, I
took a guess. ;)
Also, it is a bit of a habit on my part to use Symbols, instead of
strings or so.
| Also, you're calling params; I think you mean param.
Yes, indeed. Typo on my part (I cought it the other two chances..).
|
| You could also do:
|
| def param[]=(key,value)
| @params[key] = value
| end
|
| object.param[key] = value
Oh, I'm gonna steal that idiom if you don't mind. ;)
- --
Phillip Gawlowski
Twitter: twitter.com/cynicalryan
Blog: http://justarubyist.blogspot.com
~ "My ethicator machine must've had a built-in moral compromise
~ spectral release phantasmatron! I'm a genius!" --- Calvin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkgYb78ACgkQbtAgaoJTgL9uFwCeKmz6hTAVyts6LCR67Va7hvkF
ucQAnR8ZQiObqzUcJD+WbLGRUmnshy5i
=/Utl
-----END PGP SIGNATURE-----
.
- Follow-Ups:
- Re: How to create "def method(item)= (value)" ?
- From: David A. Black
- Re: How to create "def method(item)= (value)" ?
- From: Iñaki Baz Castillo
- Re: How to create "def method(item)= (value)" ?
- References:
- How to create "def method(item)= (value)" ?
- From: Iñaki Baz Castillo
- Re: How to create "def method(item)= (value)" ?
- From: Phillip Gawlowski
- How to create "def method(item)= (value)" ?
- Prev by Date: Re: n00b string replace
- Next by Date: Re: How to create "def method(item)= (value)" ?
- Previous by thread: Re: How to create "def method(item)= (value)" ?
- Next by thread: Re: How to create "def method(item)= (value)" ?
- Index(es):
Relevant Pages
|