From: Hidetoshi NAGAI Date: 2007-02-26T23:13:16+09:00 Subject: Re: Methods and :parameters From: "Pedro Del Gallego" Subject: Re: Methods and :parameters Date: Mon, 26 Feb 2007 22:02:56 +0900 Message-ID: <2e93189b0702260502k2fed81b8qbc49ca40b1c89e95@mail.gmail.com> > Wow ... thats exactly what i was looking for :). Can you explain me > how this override of the method_missing works? im a little bit lost > right after the when statament begin ... > > > def method_missing(id, *args) # Expect the unknown method as accessing to a property. > > prop = id.id2name # Get the method name string. > > case args.length # Check the number of arguments. > > when 1 # If one argument, it will be a setter method. > > if prop[-1] == ?= # Is it "="? (e.g. "self.property = val") # If so, call "self[] = val". > > self[prop[0..-2]] = args[0] > > args[0] > > else # Else it will be "self.property(val)". # Then call "self[] = val". > > self[prop] = args[0] > > self > > end > > when 0 # If no argument, it will be a getter method. > > self[prop] > > else # If more than one argument, it will not a setter or getter. # So use "method_missing" of the super class. > > super(id, *args) > > end > > end Are those OK? -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)