Sha256: a0496d5ff5efc74cb2fab89651315559dffc2082d55e06d36f935507c686c99a
Contents?: true
Size: 1.06 KB
Versions: 5
Compression:
Stored size: 1.06 KB
Contents
# frozen_string_literal: true module Grape module Util # Base for classes which need to operate with own values kept # in the hash and inherited values kept in a Hash-like object. class BaseInheritable attr_accessor :inherited_values, :new_values # @param inherited_values [Object] An object implementing an interface # of the Hash class. def initialize(inherited_values = nil) @inherited_values = inherited_values || {} @new_values = {} end def delete(key) new_values.delete key end def initialize_copy(other) super self.inherited_values = other.inherited_values self.new_values = other.new_values.dup end def keys if new_values.any? inherited_values.keys.tap do |combined| combined.concat(new_values.keys) combined.uniq! end else inherited_values.keys end end def key?(name) inherited_values.key?(name) || new_values.key?(name) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems