Hi,

At Thu, 12 Aug 2004 12:49:50 +0900,
Hal Fulton wrote in [ruby-talk:108944]:
> But this leads to an oddity...
> 
>    foo.delta ||= 7              # gives an error!
>    foo.delta = foo.delta || 7   # I think this also gives an error

`len' is length of `args' to messod_missing at first, not
setter's.  And I guess defined setter should fail if any
arguments given.


--- /tmp/nobu/superstruct-orig.rb 2004-08-12 15:19:33.000000000 +0900 +++ /tmp/nobu/superstruct.rb 2004-08-12 15:21:38.000000000 +0900 @@ -131,7 +131,7 @@ class SuperStruct setsyms << setter table << getter - len = args.length klass.class_eval do define_method(setter) do |*args| + len = args.length if len != 1 raise ArgumentError, "Wrong # of arguments (#{len} for 1)", @@ -141,5 +141,5 @@ class SuperStruct instance_variable_get(ivar) end - define_method(getter) do + define_method(getter) do || instance_variable_get(ivar) end @@ -148,10 +148,5 @@ class SuperStruct self.send(setter,*args) else - if len == 0 - self.send(getter) - else - raise NoMethodError, "Undefined method '#{mname}' for #{self}", - caller(1) - end + self.send(getter,*args) end end
-- Nobu Nakada