From: Peter Hickman Date: 2013-04-30T00:43:21+09:00 Subject: Re: New Rexx like data structure --047d7b343f026c2d4604db81be8e Content-Type: text/plain; charset=ISO-8859-1 On 29 April 2013 16:33, Robert Klemme wrote: > We can only make it work if you accept always getting an OpenStruct in > return > > irb(main):011:0> class OpenStruct > irb(main):012:1> alias _method_missing method_missing > irb(main):013:1> def method_missing(*a,&b) x=_method_missing(*a,&b); > x.nil? ? send("#{a.first}=", self.class.new) : x end > irb(main):014:1> end > => nil > irb(main):015:0> o=OpenStruct.new > => # > irb(main):016:0> o.foo.bar=123 > => 123 > irb(main):017:0> o > => #> > > Hmm. That doesn't seem to work for me in 1.8.7 or 1.9.2 ruby-1.9.2-p290 :001 > class OpenStruct ruby-1.9.2-p290 :002?> alias _method_missing method_missing ruby-1.9.2-p290 :003?> def method_missing(*a,&b) x=_method_missing(*a,&b); x.nil? ? send("#{a.first}=", self.class.new) : x end ruby-1.9.2-p290 :004?> end => nil ruby-1.9.2-p290 :005 > ruby-1.9.2-p290 :006 > o=OpenStruct.new => # ruby-1.9.2-p290 :007 > o.foo.bar=123 NoMethodError: undefined method `foo' for # from (irb):3:in `method_missing' from (irb):7 from /Users/peterhickman/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `
' ruby-1.9.2-p290 :008 > o => # Same error in both --047d7b343f026c2d4604db81be8e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On 29 April 2013 16:33, Robert Klemme &l= t;shortcutt= er@googlemail.com> wrote:
We can only make it work if you accept al= ways getting an OpenStruct in return

irb(main):011:0> cla= ss OpenStruct
irb(main):012:1> alias _method_missing method_mi= ssing
irb(main):013:1> def method_missing(*a,&b) x=3D_method_missing(= *a,&b); x.nil? ? send("#{a.first}=3D", self.class.new) : x en= d
irb(main):014:1> end
=3D> nil
irb(mai= n):015:0> o=3DOpenStruct.new
=3D> #<OpenStruct>
irb(main):016:0> o.foo.bar=3D= 123
=3D> 123
irb(main):017:0> o
=3D>= #<OpenStruct foo=3D#<OpenStruct bar=3D123>>


Hmm= . That doesn't seem to work for me in 1.8.7 or 1.9.2
ruby-1.9.2-p290 :001 > class OpenStruct
ruby-1.9.2-p290 :002?> =A0 alias _method_missing method_missing
ruby-1.9.2-p290 :003?> =A0 def method_missing(*a,&b) x=3D_method_m= issing(*a,&b); x.nil? ? send("#{a.first}=3D", self.class.new)= : x end
ruby-1.9.2-p290 :004?> =A0 end
=A0=3D> nil=A0
ruby-1.9.2-p290 :005 >=A0
ruby-1.9.2-p290 :006 > =A0 o=3D= OpenStruct.new
=A0=3D> #<OpenStruct:0x00000100a9c3a0>=A0=
ruby-1.9.2-p290 :007 > o.foo.bar=3D123
NoMethodError: undefined method `foo' for #<OpenStruct:0x000001= 00a9c3a0>
f= rom (irb):3:in `method_missing'
from (irb):7
from /Users/peterhi= ckman/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
ruby-1.9.2-p290 :008 > o
=A0=3D> #<OpenStruct:0x000001= 00a9c3a0>=A0

Same error in both
=A0
--047d7b343f026c2d4604db81be8e--