Class: CommandModel::Convert::StringMutator

Inherits:
Object
  • Object
show all
Defined in:
lib/command_model/convert.rb

Instance Method Summary collapse

Constructor Details

#initialize(force_to_s = false, &block) ⇒ StringMutator

Returns a new instance of StringMutator.



16
17
18
19
# File 'lib/command_model/convert.rb', line 16

def initialize(force_to_s=false, &block)
  @force_to_s = force_to_s
  @mutator = block
end

Instance Method Details

#call(value) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/command_model/convert.rb', line 21

def call(value)
  if @force_to_s
    @mutator.call value.to_s
  elsif value.respond_to? :to_str
    @mutator.call value.to_str
  else
    value
  end
end