lib/tap/support/assignments.rb in bahuvrihi-tap-0.10.7 vs lib/tap/support/assignments.rb in bahuvrihi-tap-0.10.8

- old
+ new

@@ -3,18 +3,16 @@ # Assignments defines an array of [key, values] pairs that tracks # which values are assigned to a particular key. A value may only # be assigned to one key at a time. # - # Assignments tracks the order in which keys are declared, and the + # Assignments tracks the order of key declaration, and the # order in which values are assigned to a key. This behavior is - # used by ClassConfiguration to track the order in which configurations - # are assigned to a class; the order, in turn, is used in the formation + # used by ClassConfiguration to track the order of configurations + # in a class; the order, in turn, is used in the formation # of config files, command line documentation, etc. # - # === Example - # # a = Assignments.new # a.assign(:one, 'one') # a.assign(:two, 'two') # a.assign(:one, 'ONE') # a.to_a # => [[:one, ['one', 'ONE']], [:two, ['two']]] @@ -33,10 +31,13 @@ # storage can be made faster or to take up less memory. Not that # that much can be gained period... class Assignments include Enumerable + # Generates a new Assignments using the parent array of + # [key, values] pairs. Uses parent.array if parent is + # an Assignments, or [] if parent is nil. def initialize(parent=nil) existing_array = case parent when Assignments then parent.array when Array then parent when nil then [] @@ -137,35 +138,35 @@ return values if k == key end nil end - # Yields each key, value pair in the order in which + # Yields each [key, value] pair in the order in which # the keys were declared. Keys with no values are # skipped. def each array.each do |key, values| values.each {|value| yield(key, value) } end end - # Yields each key, values pair in the order in which + # Yields each [key, values] pair in the order in which # the keys were declared. def each_pair array.each do |key, values| yield(key, values) end end - # Returns the [key, values] as an array + # Returns self as an array def to_a array.collect {|key, values| [key, values.dup] } end protected # An array of [key, values] arrays tracking the - # key and order in which values were assigned. + # order in which values are assigned. attr_reader :array end end end \ No newline at end of file