From: Jim Freeze Date: 2001-04-28T04:08:18+09:00 Subject: [ruby-talk:14346] case and to_s Hi: I am trying to add a clase to a list depending upon the type of the class. Since there are several types of classes, I am using a case statement. But, the way I am using the case statement causes the << to call #to_s, which I don't want it to do. Here is the error followed by the code. Can someone please explain this behavior to me? Tnanks ./dev.rb ./dev.rb:21:in `===': failed to convert Class into String (TypeError) from ./dev.rb:21:in `add_device' from ./dev.rb:32 from ./dev.rb:32:in `each' from ./dev.rb:32 --begin code-- #! /usr/local/bin/ruby class DeviceA def initialize(a,b) @a = a @b = b end end class Assembly def initialize @devlist = [] end def add_device(d) # This line works #@devlist << d if DeviceA == d.type # These 4 lines cause an error case d.type when /DeviceA/ @devlist << d end end end xdev = [] xdev << DeviceA.new("a","b") xdev << DeviceA.new("A","B") assembly = Assembly.new xdev.each { |x| assembly.add_device x } --end code-- ========================================================= Jim Freeze jim@freeze.org --------------------------------------------------------- No comment at this time. http://www.freeze.org =========================================================