From: Phillip Gawlowski Date: 2008-04-30T22:10:32+09:00 Subject: Re: How to create "def method(item)= (value)" ? -----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-----