Class: Hash::ValueChanger

Inherits:
Object
  • Object
show all
Defined in:
lib/hash/value_changer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, &block) ⇒ ValueChanger

Returns a new instance of ValueChanger.



4
5
6
7
8
9
10
11
# File 'lib/hash/value_changer.rb', line 4

def initialize(options, &block)
  @options = {
    recursive: true,
    skip_inner: true
  }.merge(options)

  @block = block
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



2
3
4
# File 'lib/hash/value_changer.rb', line 2

def block
  @block
end

#optionsObject

Returns the value of attribute options.



2
3
4
# File 'lib/hash/value_changer.rb', line 2

def options
  @options
end

Instance Method Details

#change(object) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/hash/value_changer.rb', line 13

def change(object)
  if object.respond_to?(:change_values)
    change_hash(object)
  elsif is_iterable?(object)
    change_array(object)
  end
end