Skip to content

Commit

Permalink
Fixed an issue with ArrayStruct not working anymore.
Browse files Browse the repository at this point in the history
  • Loading branch information
samueldr committed Mar 18, 2016
1 parent ca7c09c commit 3fb46f7
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions classes/arraystruct.rb
Expand Up @@ -68,9 +68,9 @@ def method_missing(mid, *args)
# Add the new member to the defined methods.
new_ostruct_member(mname)
# Then use it as it has custom behaviour.
self.send(mid, *args)
return self.send(mid, *args)
elsif len == 0 && mid != :[]
self[mid]
return self[mid]
else
raise NoMethodError, "undefined method `#{mid}' for #{self}", caller(1)
end
Expand Down Expand Up @@ -99,18 +99,15 @@ def each_pair
# @private
# @return The name of the new member.
def new_ostruct_member(name)
name = name.to_sym
unless respond_to?(name)
define_singleton_method(name) { @table[name] }
define_singleton_method("#{name}=") { |x|
name = name.to_sym
self.define_singleton_method(name) { @table[name] }
self.define_singleton_method("#{name}=") { |x|
#Automatically wrap in an ArrayStrucElement, unless it is an ArrayStructElement
if not x.is_a?(ArrayStructElement) then
x = ArrayStructElement.new(x)
end
@table[name] = x
modifiable[name] = x
}
end
name
end
end

Expand Down

0 comments on commit 3fb46f7

Please sign in to comment.