class ExtrudingHash
Public Instance Methods
<<( right )
click to toggle source
Add a column into the structure. Respect any bins already in the structure, and add nil values to any existing columns that haven’t included the bins of the newly passed-in column.
# File lib/extruding-hash/extruding_hash.rb, line 30 def <<( right ) unless right.nil? right.each_key do |key| self[key] = Array.new if self[key].nil? end self.normalize! right.each do |key, value| self[key] << value end self.normalize! end return self end
columns()
click to toggle source
The (largest) number of columns among all bins of the Hash.
# File lib/extruding-hash/extruding_hash.rb, line 47 def columns ret = -1 self.each do |key, value| ret = value.count if value.count > ret end if ret < 0 nil else ret end end
normalize!()
click to toggle source
Grow any extent short rows to the same width as the longest
# File lib/extruding-hash/extruding_hash.rb, line 61 def normalize! max = self.columns self.each do |key, value| value << nil while value.count < max end max end
set_from_hash( right )
click to toggle source
Set this sub-class of hash to the passed hash.
# File lib/extruding-hash/extruding_hash.rb, line 22 def set_from_hash( right ) right.each { |k,v| self[k] = v } return self end