Sha256: 8023f122e0583be034071f4309d9c26543f194ae62797ebfed1bb4cbae3f9dd5
Contents?: true
Size: 877 Bytes
Versions: 4
Compression:
Stored size: 877 Bytes
Contents
module AttrMethods def attr_array(*names) names.each do |n| self.send :define_method, n do |*value| if value.nil? || value.empty? return instance_variable_get("@#{n}") else self.send "#{n}=".to_sym, value.to_ary.flatten end end self.send :define_method, "#{n}=" do |value| instance_variable_set("@#{n}", value) end end end def attr_hash(*names) names.each do |n| self.class_eval(<<-EOF, __FILE__, __LINE__) def #{n}(*value) if value.nil? || value.empty? instance_variable_get("@#{n}") else instance_variable_set("@#{n}", value[0]) end end EOF self.send :define_method, "#{n}=" do |value| instance_variable_set("@#{n}", value) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems