Module: Lab42::OpenMap::Implementation
- Included in:
- Lab42::OpenMap
- Defined in:
- lib/lab42/open_map/implementation.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
|
# 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
|
Instance Method Details
#[]=(key, value) ⇒ Object
6
7
8
9
|
# 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) ⇒ Object
11
12
13
|
# File 'lib/lab42/open_map/implementation.rb', line 11
def deconstruct_keys(keys)
@hash.slice(*keys)
end
|
#merge(**kwds) ⇒ Object
15
16
17
18
|
# 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) ⇒ Object
20
21
22
|
# File 'lib/lab42/open_map/implementation.rb', line 20
def sans(*keys)
self.class.new(**without(*keys))
end
|
#to_h ⇒ Object
29
30
31
|
# File 'lib/lab42/open_map/implementation.rb', line 29
def to_h
@hash.clone
end
|
#update(**kwds) ⇒ Object
24
25
26
27
|
# File 'lib/lab42/open_map/implementation.rb', line 24
def update(**kwds)
_check_symbolic_keys!(kwds)
@hash.update(kwds)
end
|
#without(*keys) ⇒ Object
33
34
35
36
37
38
|
# 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
|