From: "Ara.T.Howard" Date: 2005-10-15T11:09:17+09:00 Subject: Re: Factory function like Array() for your own classes On Sat, 15 Oct 2005, Sean O'Halpin wrote: > I think this is a very natural idiom which doesn't seem to have any > unwelcome side-effects. I'm curious what the general opinion is. It seems a > cleaner solution than,say, aliasing [] to new (which I used to do a lot). > > So... what do you think? not a bad idea harp:~ > cat a.rb Kernel::methods.grep(%r/[A-Z]/).each do |meth| obj = send meth, 42 puts "#{ meth }(42) => #{ obj.inspect } - #{ obj.class }" end harp:~ > ruby a.rb Integer(42) => 42 - Fixnum Float(42) => 42.0 - Float String(42) => "42" - String Array(42) => [42] - Array ;-) -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | anything that contradicts experience and logic should be abandoned. | -- h.h. the 14th dalai lama ===============================================================================