Class: Code::Object::Dictionnary
Instance Attribute Summary collapse
Instance Method Summary
collapse
#<=>, #==, #falsy?, #hash, #truthy?
Constructor Details
#initialize(raw = {}) ⇒ Dictionnary
Returns a new instance of Dictionnary.
6
7
8
|
# File 'lib/code/object/dictionnary.rb', line 6
def initialize(raw = {})
@raw = raw
end
|
Instance Attribute Details
Returns the value of attribute raw.
4
5
6
|
# File 'lib/code/object/dictionnary.rb', line 4
def raw
@raw
end
|
Instance Method Details
27
28
29
|
# File 'lib/code/object/dictionnary.rb', line 27
def [](key)
raw[key]
end
|
#[]=(key, value) ⇒ Object
31
32
33
|
# File 'lib/code/object/dictionnary.rb', line 31
def []=(key, value)
raw[key] = value
end
|
#call(**args) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/code/object/dictionnary.rb', line 10
def call(**args)
operator = args.fetch(:operator, nil)
arguments = args.fetch(:arguments, [])
if operator == "values"
values(arguments)
elsif key?(operator)
fetch(operator)
else
super
end
end
|
#fetch(key) ⇒ Object
23
24
25
|
# File 'lib/code/object/dictionnary.rb', line 23
def fetch(key)
raw.fetch(key)
end
|
43
44
45
|
# File 'lib/code/object/dictionnary.rb', line 43
def inspect
to_s
end
|
35
36
37
|
# File 'lib/code/object/dictionnary.rb', line 35
def key?(key)
raw.key?(key)
end
|
39
40
41
|
# File 'lib/code/object/dictionnary.rb', line 39
def to_s
"{#{raw.map { |key, value| "#{key.inspect} => #{value.inspect}" }.join(", ")}}"
end
|