lib/osheet/associations.rb in osheet-0.4.0 vs lib/osheet/associations.rb in osheet-0.5.0

- old
+ new

@@ -18,22 +18,18 @@ singular = plural.to_s.sub(/s$/, '') klass = Osheet.const_get(singular.capitalize) # define collection reader self.send(:define_method, plural, Proc.new do - if instance_variable_get("@#{plural}").nil? - instance_variable_set("@#{plural}", []) - end - instance_variable_get("@#{plural}") + set_ivar(plural, []) if get_ivar(plural).nil? + get_ivar(plural) end) # define collection item writer self.send(:define_method, singular) do |*args, &block| - if instance_variable_get("@#{plural}").nil? - instance_variable_set("@#{plural}", []) - end - instance_variable_get("@#{plural}") << if self.respond_to?(:workbook) + set_ivar(plural, []) if get_ivar(plural).nil? + push_ivar(plural, if self.respond_to?(:workbook) # on: worksheet, column, row # creating: column, row, cell worksheet = self.respond_to?(:worksheet) ? self.worksheet : self if self.workbook && (template = self.workbook.templates.get(singular, args.first)) # add by template @@ -50,10 +46,10 @@ klass.new(self, *args[1..-1], &template) else # add by block klass.new(self, &block) end - end + end) end end end