From: Jim Freeze Date: 2001-04-28T04:55:36+09:00 Subject: [ruby-talk:14349] Re: case and to_s On Sat, 28 Apr 2001, David Alan Black wrote: > This is in effect performing the test: > > /DeviceA/ === d.type > > but Regexp#=== (case equality method for Regexp) expects a String on > the other end of the line, not a Class. > > You could force a regexp-to-string test: > > case d.type.to_s > (etc.) > I just figured this out. case d.type.to_s when "DeviceA" I was hoping to be able to case d.type when DeviceA since in an if I can do if DeviceA == d.type but no luck, so, I will stick with your first suggestion. Thanks > Or you could do: > > case d > when DeviceA > (etc.) > > because then your test is: > > DeviceA === d > > and Module#===, to paraphrase the pickaxe (p. 345), will return true > if d is an instance of DeviceA or one of DeviceA's descendants. (The > descendants part may not be desireable, but you can always use the > string-based test above instead.) > > ========================================================= Jim Freeze jim@freeze.org --------------------------------------------------------- No comment at this time. http://www.freeze.org =========================================================