From: Peter Hickman Date: 2013-04-30T00:32:40+09:00 Subject: Re: New Rexx like data structure --001a11c397ba3bff7e04db8198c2 Content-Type: text/plain; charset=ISO-8859-1 On 29 April 2013 16:23, Joel Pearson wrote: > How about this? > > class Hash > def method_missing(m, *args, &block) > key = m.to_s > if key =~ /(.*)=$/ > self.store($1, args.first) > elsif self[key] == nil && key =~ /(.*)=$/ > self.store(key, Hash.new) > else > self[key] > end > end > end > Unfortunately is breaks a.c.d = 12 *NoMethodError:* undefined method `d=' for nil:NilClass I suspect that 'c' has been turned into a nil --001a11c397ba3bff7e04db8198c2 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On 29 April 2013 16:23, Joel Pearson <= ;lists@ruby-forum= .com> wrote:
How about this?

class Hash
=A0 def method_missing(m, *args, &block)
=A0 =A0 key =3D m.to_s
=A0 =A0 if key =3D~ /(.*)=3D$/
=A0 =A0 =A0 self.store($1, args.first)
=A0 =A0 elsif self[key] =3D=3D nil && key =3D~ /(.*)=3D$/
=A0 =A0 =A0 self.store(key, Hash.new)
=A0 =A0 else
=A0 =A0 =A0 self[key]
=A0 =A0 end
=A0 end
end

Unfortunately is = breaks

a.c.d =3D 12
NoMethodError: undefined method `= d=3D' for nil:NilClass

I suspect t= hat 'c' has been turned into a nil

--001a11c397ba3bff7e04db8198c2--