Class: Code::Object
- Inherits:
-
Object
show all
- Includes:
- Comparable
- Defined in:
- lib/code/object.rb,
lib/code/object/list.rb,
lib/code/object/range.rb,
lib/code/object/number.rb,
lib/code/object/string.rb,
lib/code/object/boolean.rb,
lib/code/object/decimal.rb,
lib/code/object/integer.rb,
lib/code/object/nothing.rb,
lib/code/object/argument.rb,
lib/code/object/function.rb,
lib/code/object/dictionnary.rb
Defined Under Namespace
Classes: Argument, Boolean, Decimal, Dictionnary, Function, Integer, List, Nothing, Number, Range, String
Instance Method Summary
collapse
Instance Method Details
#<=>(other) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/code/object.rb', line 46
def <=>(other)
if respond_to?(:raw)
if other.respond_to?(:raw)
raw <=> other.raw
else
raw <=> other
end
else
other <=> self
end
end
|
#==(other) ⇒ Object
Also known as:
eql?
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/code/object.rb', line 58
def ==(other)
if respond_to?(:raw)
if other.respond_to?(:raw)
raw == other.raw
else
raw == other
end
else
other == self
end
end
|
28
29
30
31
|
# File 'lib/code/object.rb', line 28
def [](key)
@attributes ||= {}
@attributes[key]
end
|
#[]=(key, value) ⇒ Object
23
24
25
26
|
# File 'lib/code/object.rb', line 23
def []=(key, value)
@attributes ||= {}
@attributes[key] = value
end
|
#call(**args) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/code/object.rb', line 5
def call(**args)
operator = args.fetch(:operator, nil)
arguments = args.fetch(:arguments, [])
if %w[== === !=].detect { |o| operator == o }
comparaison(operator.to_sym, arguments)
elsif operator == "<=>"
compare(arguments)
elsif operator == "&&"
and_operator(arguments)
elsif operator == "||"
or_operator(arguments)
else
raise ::Code::Error::Undefined.new(
"#{operator} not defined on #{inspect}",
)
end
end
|
42
43
44
|
# File 'lib/code/object.rb', line 42
def falsy?
!truthy?
end
|
71
72
73
74
75
76
77
|
# File 'lib/code/object.rb', line 71
def hash
if respond_to?(:raw)
[self.class, raw].hash
else
raise NotImplementedError
end
end
|
33
34
35
36
|
# File 'lib/code/object.rb', line 33
def key?(key)
@attributes ||= {}
@attributes.key?(key)
end
|
79
80
81
|
# File 'lib/code/object.rb', line 79
def to_s
raise NotImplementedError
end
|
38
39
40
|
# File 'lib/code/object.rb', line 38
def truthy?
true
end
|