From: Phillip Gawlowski Date: 2008-04-30T23:02:05+09:00 Subject: Re: How to create "def method(item)= (value)" ? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 David A. Black wrote: |> |> Sort of. As a singleton method, you get the syntax error. But not if you |> define [] as a method: |> |> irb(main):001:0> def []=(key,value) |> irb(main):002:1> end |> => nil | | It's not the singletonness that stops it; you can do this: | | def object.[]=(k,v) # etc. | | What made my example wrong was that I had concocted an illegal method | name. Though, it should (might?) be possible to implemetn something like Hash's or Array's hash[key] array[index] index methods for plain old object instances, too. I haven't seen such an implementation, though, and my C and Java fu are too weak to make sense of JRuby or CRuby. Maybe Rubinius is a starting point, since it supposedly implement core classes in Ruby. - -- Phillip Gawlowski Twitter: twitter.com/cynicalryan Blog: http://justarubyist.blogspot.com ABORT: Drivel filter is compromised! -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkgYe9kACgkQbtAgaoJTgL+gSwCghRVTOxl1IlMKSoNZzq98d1F1 +88AnRieQmvx+CEX4pidn6qfqJe/5TT7 =3zqI -----END PGP SIGNATURE-----