module Lab42::OpenMap::Implementation

Public Instance Methods

[]=(key, value) click to toggle source
# File lib/lab42/open_map/implementation.rb, line 6
def []=(key, value)
  raise ArgumentError, "#{key.inspect} is not a symbol" unless Symbol === key
  @hash[key] = value
end
deconstruct_keys(keys) click to toggle source
# File lib/lab42/open_map/implementation.rb, line 11
def deconstruct_keys(keys)
  @hash.slice(*keys)
end
merge(**kwds) click to toggle source
# File lib/lab42/open_map/implementation.rb, line 15
def merge(**kwds)
  _check_symbolic_keys!(kwds)
  self.class.new(**@hash.merge(kwds))
end
sans(*keys) click to toggle source
# File lib/lab42/open_map/implementation.rb, line 20
def sans(*keys)
  self.class.new(**without(*keys))
end
to_h() click to toggle source
# File lib/lab42/open_map/implementation.rb, line 29
def to_h
  @hash.clone
end
update(**kwds) click to toggle source
# File lib/lab42/open_map/implementation.rb, line 24
def update(**kwds)
  _check_symbolic_keys!(kwds)
  @hash.update(kwds)
end
without(*keys) click to toggle source
# File lib/lab42/open_map/implementation.rb, line 33
def without(*keys)
  ( self.keys - keys.flatten )
    .inject( {} ) do |r, k|
      r.update(k => self[k])
    end
end

Private Instance Methods

_check_symbolic_keys!(kwds) click to toggle source
# File lib/lab42/open_map/implementation.rb, line 42
def _check_symbolic_keys!(kwds)
  invalid_kwds = kwds.keys.reject{Symbol === _1}
  raise ArgumentError, "the following keys are not symbols: #{invalid_kwds.inspect}" unless
    invalid_kwds.empty?
end
method_missing(name, *args) click to toggle source
Calls superclass method
# File lib/lab42/open_map/implementation.rb, line 48
def method_missing(name, *args)
  assignment = name[-1] == "="
  name = name[0..-2].to_sym if assignment
  super unless has_key?(name)
  if assignment
    raise ArgumentError, "assignment needs a value" if args.empty?
    self[name] = args.first
  else
    self[name]
  end
end