From: Xeno Campanoli Date: 2010-01-21T09:16:07+09:00 Subject: Re: Looking for object.inherits?(Classname) Walton Hoops wrote: > On 1/20/2010 2:36 PM, Walton Hoops wrote: >> On 1/20/2010 12:05 PM, Xeno Campanoli wrote: >>> Robert Klemme wrote: >>>> 2010/1/20 Xeno Campanoli : >>>>> I'm looking for a way to make sure an object being passed is in >>>>> some class >>>>> family, or to say it otherwise, inherits some specific class, but not >>>>> necessarily directly. In fact, it could be a >>>>> great-great-grandparent class, >>>>> and that would be okay, and needs to be okay. Is there something >>>>> where I >>>>> can take an object and go >>>>> >>>>> unless object.inherits?(MyClass) >>>>> raise SyntaxError, "etc." >>>>> end >>>> >>>> First of all that would not be a SyntaxError because the syntax is not >>>> affected. Using this error type will create misleading error >>>> messages. >>> >>> If I want a method that only takes objects of family Xclass, and I >>> get one passed that is not in that family, isn't that a syntax >>> error? Bad type passed in that argument place? What's the >>> difference between that and passing a string when it needs say an array? >> >> Nope, that's an ArgumentError. Example: >> irb(main):001:0> Integer("boo") >> ArgumentError: invalid value for Integer: "boo" >> from (irb):2 >> irb(main):002:0> >> >> Integer("boo") syntactically correct, yet "boo" is not a valid >> argument for this function. >> > Whoops, my bad, actually the situation you describe is a TypeError: > irb(main):002:0> Integer([1,2,3]) > TypeError: can't convert Array into Integer > from (irb):3 > irb(main):003:0> > > again, still syntactically sound, but Integer can't take an array. Okay. Good. Thanks. I appreciate the feedback. This will help my programming, perhaps semantically I guess I should say. Sincerely, Xeno > > -- Harping Statements about Harry Reid's Comments make profusely corrupt and racist staff at Fox News feel somehow a little less evil looking than they in fact are.