class HashGenerator

Constants

VERSION

Public Class Methods

new() click to toggle source
# File lib/hash_generator.rb, line 4
def initialize
  @value = @scope = {}
  @stack = []
end

Public Instance Methods

end_scope() click to toggle source
# File lib/hash_generator.rb, line 9
def end_scope
  @scope = @stack.pop
end
new_array() click to toggle source
# File lib/hash_generator.rb, line 13
def new_array
  begin_scope([])
end
new_object() click to toggle source
# File lib/hash_generator.rb, line 17
def new_object
  begin_scope({})
end
push_object() { || ... } click to toggle source
# File lib/hash_generator.rb, line 21
def push_object
  new_object
  yield
  push_scope
end
push_scope() click to toggle source
# File lib/hash_generator.rb, line 27
def push_scope
  value = @scope
  end_scope
  push(value)
end
reopen_scope(key) click to toggle source
# File lib/hash_generator.rb, line 33
def reopen_scope(key)
  begin_scope(@scope.fetch(key))
end
store(key, value) click to toggle source
# File lib/hash_generator.rb, line 37
def store(key, value)
  @scope.store(key, value)
end
store_array(key) { || ... } click to toggle source
# File lib/hash_generator.rb, line 41
def store_array(key)
  new_array
  yield
  store_scope(key)
end
store_object(key) { || ... } click to toggle source
# File lib/hash_generator.rb, line 47
def store_object(key)
  new_object
  yield
  store_scope(key)
end
store_scope(key) click to toggle source
# File lib/hash_generator.rb, line 53
def store_scope(key)
  value = @scope
  end_scope
  store(key, value)
end
to_h() click to toggle source
# File lib/hash_generator.rb, line 59
def to_h
  @value
end
Also aliased as: to_hash
to_hash()
Alias for: to_h

Private Instance Methods

begin_scope(scope) click to toggle source
# File lib/hash_generator.rb, line 67
def begin_scope(scope)
  @stack.push(@scope)
  @scope = scope
end
push(value) click to toggle source
# File lib/hash_generator.rb, line 72
def push(value)
  @scope.push(value)
end