From: Chris Date: 2002-04-05T02:52:18+09:00 Subject: Re: Some ActiveRuby/RubyScript questions In article , Chris wrote: > In article <5.1.0.14.0.20020404153158.01dea910@pop3.bip.net>, > Liorean wrote: > > > Also, I'd like to know how to detect whether a property of an object exists > > or not, something of the kind: > > if(typeof document.all!='undefined'){/* some action or other... */} > > an_array = [] > > if defined?(an_array.push) > #do something here > end > > or... > > if x = defined? an_array.push > p x > end > > prints out "method" There's also this nasty eval() solution: class Object def has_attr?(attr_name) not defined?(eval("self.#{attr_name}")).nil? end end an_array = [] an_array.has_attr?("push")