Class: Remi::Fields
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Remi::Fields
- Defined in:
- lib/remi/fields.rb
Instance Method Summary collapse
- #dup ⇒ Object
-
#initialize(fields = Hash.new({})) ⇒ Fields
constructor
A new instance of Fields.
- #merge(other_fields, prefix: nil) ⇒ Object
- #merge!(other_fields, prefix: nil) ⇒ Object
Constructor Details
#initialize(fields = Hash.new({})) ⇒ Fields
Returns a new instance of Fields.
3 4 5 6 |
# File 'lib/remi/fields.rb', line 3 def initialize(fields=Hash.new({})) @fields = Hash.new({}).merge fields super(@fields) end |
Instance Method Details
#merge(other_fields, prefix: nil) ⇒ Object
13 14 15 |
# File 'lib/remi/fields.rb', line 13 def merge(other_fields, prefix: nil) dup.merge!(other_fields, prefix: prefix) end |
#merge!(other_fields, prefix: nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/remi/fields.rb', line 17 def merge!(other_fields, prefix: nil) @fields.merge!(other_fields) do |key, this_val, other_val| if prefix @fields["#{prefix}#{key}".to_sym] = other_val this_val else this_val.merge other_val end end end |