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/global.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,
lib/code/object/ruby_function.rb
Defined Under Namespace
Classes: Argument, Boolean, Decimal, Dictionnary, Function, Global, Integer, List, Nothing, Number, Range, RubyFunction, String
Instance Method Summary
collapse
Instance Method Details
#<=>(other) ⇒ Object
58
59
60
61
62
63
64
|
# File 'lib/code/object.rb', line 58
def <=>(other)
if respond_to?(:raw)
other.respond_to?(:raw) ? raw <=> other.raw : raw <=> other
else
other <=> self
end
end
|
#==(other) ⇒ Object
Also known as:
eql?
66
67
68
69
70
71
72
|
# File 'lib/code/object.rb', line 66
def ==(other)
if respond_to?(:raw)
other.respond_to?(:raw) ? raw == other.raw : raw == other
else
other == self
end
end
|
#call(**args) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/code/object.rb', line 5
def call(**args)
operator = args.fetch(:operator, nil)
arguments = args.fetch(:arguments, [])
value = arguments.first&.value
if operator == "=="
sig(arguments) { ::Code::Object }
equal(value)
elsif operator == "==="
sig(arguments) { ::Code::Object }
strict_equal(value)
elsif operator == "!="
sig(arguments) { ::Code::Object }
different(value)
elsif operator == "<=>"
sig(arguments) { ::Code::Object }
compare(value)
elsif operator == "&&" || operator == "and"
sig(arguments) { ::Code::Object }
and_operator(value)
elsif operator == "||" || operator == "or"
sig(arguments) { ::Code::Object }
or_operator(value)
elsif operator == "!" || operator == "not"
sig(arguments)
exclamation_point
elsif operator == "+"
sig(arguments)
self
elsif operator == ".."
sig(arguments) { ::Code::Object }
inclusive_range(value)
elsif operator == "..."
sig(arguments) { ::Code::Object }
exclusive_range(value)
elsif operator == "to_string"
sig(arguments)
to_string
else
raise(
Code::Error::Undefined.new("#{operator} not defined on #{inspect}")
)
end
end
|
54
55
56
|
# File 'lib/code/object.rb', line 54
def falsy?
!truthy?
end
|
75
76
77
78
79
80
81
|
# File 'lib/code/object.rb', line 75
def hash
if respond_to?(:raw)
[self.class, raw].hash
else
raise NotImplementedError.new(self.class.name)
end
end
|
83
84
85
|
# File 'lib/code/object.rb', line 83
def to_s
raise NotImplementedError.new(self.class.name)
end
|
50
51
52
|
# File 'lib/code/object.rb', line 50
def truthy?
true
end
|