lib/nugrant/bag.rb in nugrant-1.2.0 vs lib/nugrant/bag.rb in nugrant-1.3.0
- old
+ new
@@ -40,11 +40,11 @@
current = @__elements[key]
if current.kind_of?(Bag) and value.kind_of?(Bag)
current.__merge!(value)
elsif current.kind_of?(Array) and value.kind_of?(Array)
@__elements[key] = current | value
- else
+ elsif value != nil
@__elements[key] = value
end
next
end
@@ -57,15 +57,19 @@
@__elements.each do |key, value|
yield key, value
end
end
- def __to_hash()
+ def __to_hash(options = {})
return {} if empty?()
+ string_key = options[:string_key]
+
hash = {}
each do |key, value|
- hash[key] = value.kind_of?(Bag) ? value.__to_hash() : value
+ key = key.to_s() if string_key
+
+ hash[key] = value.kind_of?(Bag) ? value.__to_hash(:string_key => string_key) : value
end
return hash
end