From: 7stud -- Date: 2008-03-09T13:39:59+09:00 Subject: Re: A question on singleton methods 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 > a_hash = { :a => "alpha", :b => "beta" } val = a_hash.fetch(:a) puts val.class #String $ri String#to_s ------------------------------------------------------------ String#to_s str.to_s => str str.to_str => str ------------------------------------------------------------------------ Returns the receiver. And you don't define methods like this: def "sayhi" puts 'hi' end You define them like this: def sayhi puts 'hi' end A method name is not a string. -- Posted via http://www.ruby-forum.com/.