Class: ReversableTech::Reverter

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

Constant Summary collapse

AVAILABLE_ENTITIES =
{
  String => [:reverse],
  Array => [:reverse],
  Hash => %i[to_a reverse to_h]
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(entity) ⇒ Reverter

Returns a new instance of Reverter.



11
12
13
# File 'lib/reversable_tech.rb', line 11

def initialize(entity)
  @entity = entity
end

Instance Method Details

#callObject



15
16
17
# File 'lib/reversable_tech.rb', line 15

def call
  AVAILABLE_ENTITIES[@entity.class].inject(@entity) { |entity, method| entity.__send__(method) }
end