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-----

.



Relevant Pages

  • Re: simple question
    ... Hash: SHA1 ... I have a string like this ... "Programming in Java is like dealing with your mom -- ... Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org ...
    (comp.lang.ruby)
  • Re: Hash or Tree
    ... Hash: SHA1 ... The key is a string, ... The HashMap is written to once upon ... Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org ...
    (comp.lang.java.programmer)
  • Re: String Length and Accessing Individual Characters
    ... Hash: SHA1 ... If you want dertermine the length of a unicode string, ... Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org ...
    (perl.beginners)
  • Re: How to write a diff in VB6 for comparing two xml files?
    ... No, the best you could do is to read both into string and use StrCompbut it's inefficient and, but using the hash ... Private Declare Function CryptAcquireContext Lib "AdvAPI32.dll" Alias _ ... Dim HashAAs Byte, HashLenA As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: something like switch in c
    ... >> straightforward string comparisions. ... > inner table size and/or add symbols to expand the hash. ... It all depends on the empirical pattern of the actual keys. ... The value of the random number generator is UNCHANGED on ...
    (comp.programming)