From: "Morris, Chris" Date: 2001-10-27T05:40:47+09:00 Subject: [ruby-talk:23526] RE: Capture undefined method calls? Thanks for all the helpful replies. I must say, Ruby is very cool. Here's what I came up with: class NodeWrapper def initialize(domNode) @domNode = domNode end def method_missing(methID, *args) property = methID.id2name if property[-1, 1] == '=' if @domNode.elements(property.chop) == nil assert(false, property + ' is not a valid property') else @domNode.send(property, *args) end else @domNode.send(property, *args) end end end > -----Original Message----- > From: Morris, Chris [mailto:chris.morris@snelling.com] > Sent: Friday, October 26, 2001 12:57 PM > To: ruby-talk@ruby-lang.org > Subject: [ruby-talk:23481] Capture undefined method calls? > > > I've got the following line: > > document.form.ObjectID.value = 'x' > > form currently is an html dom node. What I'd like to do is > something like > (psuedo code falling out all over the place): > > def form > # return a wrapper for the node > NodeWrapper.new(document.form) > end > > class NodeWrapper > def initialize(node) > @node = node > end > > def someSortOfCatchAllForUndefinedCalls(*args) > propName = nameOfUndefinedMethod # e.g. ObjectID > if @node.hasProperty(propName) > @node.propName.value = args[0] > else > assert(false, 'property does not exist') > end > end > end > > then I could simplify the initial call to: > > form.ObjectID = 'x' # maybe, haven't accounted for = sign > > ... and get some additional testing code. Hmmm, well I'm not > sure if this > would be that useful to me now that I've thought it through, > but I'm still > curious if Ruby can do this sort of thing ... it seems like it could. > > Chris >