From: Jeff Swope Date: 2008-03-09T09:22:26+09:00 Subject: Re: A question on singleton methods ------=_Part_16205_15291769.1205022150661 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline unsubscribe On Sat, Mar 8, 2008 at 6:34 PM, mike leonard wrote: > Hello, > > I have a hash full of objects, like so: > > a_hash = { :a => "alpha", :b => "beta" } > > I don't I need to define a singleton method for one of the items in > the class. I thought I could do: > > def a_hash.fetch(:a).to_s > "ALPHA" > end > > But all this gets me is a big fat error: > > t.rb:2: syntax error, unexpected tSYMBEG, expecting ')' > def a_hash.fetch(:a).to_s > ^ > > This is just a minimal example. In real life, the objects in the hash > have been generated programatically, so I don't have variable > references for them -- just the keys. > > Is it possible that there is a way around this error? If not, is there > another way to do what I'm trying to do? I'm pretty new to this, so > apologies in advance if it is an obvious mistake. > > Thank you, > > Mike Leonard > > ------=_Part_16205_15291769.1205022150661--