Class: Destruct

Inherits:
Object
  • Object
show all
Defined in:
lib/destruct.rb,
lib/destruct/dsl.rb,
lib/destruct/hash.rb,
lib/destruct/object.rb,
lib/destruct/resolver.rb

Defined Under Namespace

Modules: Object Classes: DSL, Hash, Resolver

Constant Summary collapse

GEMSPEC =
File.expand_path("../../destruct.gemspec", __FILE__)
VERSION =
Gem::Specification.load(GEMSPEC).version.to_s

Instance Method Summary collapse

Constructor Details

#initialize(object, *paths, &block) ⇒ Destruct

Returns a new instance of Destruct.



12
13
14
15
16
# File 'lib/destruct.rb', line 12

def initialize(object, *paths, &block)
  @object = object
  @paths = paths
  @block = block || proc { }
end

Instance Method Details

#to_hObject



18
19
20
21
22
23
24
# File 'lib/destruct.rb', line 18

def to_h
  paths.each_with_object(Hash.new) do |path, hash|
    resolve(path).each do |key, value|
      hash[key] = value
    end
  end
end