lib/usable/struct.rb in usable-3.7.1 vs lib/usable/struct.rb in usable-3.8.0

- old
+ new

@@ -1,20 +1,31 @@ module Usable def self.Struct(attributes = {}) Class.new do extend Usable - self.usables = Usable::Config.new(attributes) - - attributes.keys.each do |key| + define_usable_accessors + attributes.keys.map(&:to_sym).each do |key| define_method(key) { @attrs[key] } define_method("#{key}=") { |new_val| @attrs[key] = new_val } end attr_accessor :attrs def initialize(attrs = {}) @attrs = usables.merge(attrs) + end + + def [](key) + @attrs[key] + end + + def []=(key, val) + @attrs[key] = val + end + + def each(&block) + @attrs.each(&block) end end end end