> > The OO way is to use a mapping IMHO: > > > > ACTION_MAPPING = { > > Fixnum => lambda { puts "Fixnum" }, > > Float => lambda { puts "Float" }, > > String => lambda { puts "String" }, > > } > > > > def myfunc(klass) > > code = ACTION_MAPPING[klass] > > raise ArgumentError, "Klass not found: #{klass}" unless code > > code.call > > end > > > > You can even define a block for the error as default > > effectively rendering the method a one liner like this: > > > > ACTION_MAPPING = Hash.new( lambda { raise ArgumentError, > > "Klass not found" } ).update( > > Fixnum => lambda { puts "Fixnum" }, > > Float => lambda { puts "Float" }, > > String => lambda { puts "String" } > > ) > > > > def myfunc(klass) ACTION_MAPPING[klass].call end But what about duck typing? This was asked (IIRC) earlier on this thread but (again IIRC) not addressed. The duck typing way would be to not depend on the class of the objects in the first place. In the given example it would be something like: puts x.class.to_s which works for all classes, old, new, borrowed, blue. If the original poster is still reading, what is the real application? Is there some reason you need to know the class, or do you just need to assure that the class has some behaviour? -- Markus