How to simplify "a.instance_of? classX or a.instance_of? cla

Hi all,

I would like to know if there is a way to simplify this code

object.instance_of? WSDL::XMLSchema::ComplexContent or
    object.instance_of? WSDL::XMLSchema::ComplexType or
    object.instance_of? WSDL::XMLSchema::SimpleType or
    object.instance_of? WSDL::XMLSchema::SimpleRestriction or
    object.instance_of? WSDL::XMLSchema::Element or
    object.instance_of? WSDL::XMLSchema::Sequence or
    object.instance_of? XSD::QName or
    object.instance_of? WSDL::Message or
    object.instance_of? WSDL::Part or
    object.instance_of? WSDL::Service or
    object.instance_of? WSDL::Port or
    object.instance_of? WSDL::SOAP::Address or
    object.instance_of? WSDL::Binding or
    object.instance_of? WSDL::SOAP::Binding or
    object.instance_of? WSDL::OperationBinding or
    object.instance_of? WSDL::SOAP::Operation or
    object.instance_of? WSDL::Param or
    object.instance_of? WSDL::SOAP::Body or
    object.instance_of? WSDL::PortType or
    object.instance_of? WSDL::Operation or
    object.instance_of? WSDL::SOAP::Attribute

?

Thanks

On Nov 3, 2006, at 6:10 PM, Stephane W. wrote:

    object.instance_of? XSD::QName or
    object.instance_of? WSDL::SOAP::Body or
    object.instance_of? WSDL::PortType or
    object.instance_of? WSDL::Operation or
    object.instance_of? WSDL::SOAP::Attribute

?

Thanks

[
WSDL::XMLSchema::ComplexContent,
WSDL::XMLSchema::ComplexType,
WSDL::XMLSchema::SimpleType,
WSDL::XMLSchema::SimpleRestriction,
WSDL::XMLSchema::Element,
WSDL::XMLSchema::Sequence,
XSD::QName,
WSDL::Message,
WSDL::Part,
WSDL::Service,
WSDL::Port,
WSDL::soap::Address,
WSDL::Binding,
WSDL::soap::Binding,
WSDL::OperationBinding,
WSDL::soap::Operation,
WSDL::Param,
WSDL::soap::Body,
WSDL::PortType,
WSDL::Operation,
WSDL::soap::Attribute
].any? {|cls| object.instance_of? cls}

Thats one way to skin this cat. But I have to call code smell on

this whole check to see if this object is an instance of all these
classes. Maybe there is an easier way to accomplish what you want if
you expound on the question?

Cheers-
– Ezra Z.
– Lead Rails Evangelist
[email protected]
– Engine Y., Serious Rails Hosting
– (866) 518-YARD (9273)

If any are subclasses of the other’s then use only the superclass.

T.

Le 4 novembre 2006 à 04:57, Phrogz a écrit :

WSDL::XMLSchema::SimpleType
# your code here
end

Maybe more legible (and allows you to reuse the test) :

LIST = [ WSDL::XMLSchema::ComplexContent,
WSDL::XMLSchema::ComplexType,
WSDL::XMLSchema::SimpleType,

]

case object
when *LIST

end

Fred

Stephane W. wrote:

I would like to know if there is a way to simplify this code

object.instance_of? WSDL::XMLSchema::ComplexContent or
object.instance_of? WSDL::XMLSchema::ComplexType or
object.instance_of? WSDL::XMLSchema::SimpleType or
[snip]

case object
when WSDL::XMLSchema::ComplexContent, WSDL::XMLSchema::ComplexType,
WSDL::XMLSchema::SimpleType
# your code here
end

For example:

irb(main):001:0> class Foo; end; class Bar; end; class Jimmy; end
=> nil
irb(main):002:0> o = Bar.new
=> #Bar:0x356f74
irb(main):003:0> case o; when Foo, Bar; p “yay”; else; p “boo”; end
“yay”
=> nil
irb(main):004:0> o = Jimmy.new
=> #Jimmy:0x34416c
irb(main):005:0> case o; when Foo, Bar; p “yay”; else; p “boo”; end
“boo”
=> nil

F. Senault wrote:

when *LIST

end

Fred

Very nice.