You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/lib/gitlab-cli/lib/gitlab/objectified_hash.rb

25 lines
567 B

module Gitlab
# Converts hashes to the objects.
class ObjectifiedHash
# Creates a new ObjectifiedHash object.
def initialize(hash)
@hash = hash
@data = hash.inject({}) do |data, (key,value)|
value = ObjectifiedHash.new(value) if value.is_a? Hash
data[key.to_s] = value
data
end
end
def to_hash
@hash
end
alias_method :to_h, :to_hash
# Delegate to ObjectifiedHash.
def method_missing(key)
@data.key?(key.to_s) ? @data[key.to_s] : nil
end
end
end