Class: Code::Object::Boolean
Instance Attribute Summary
Attributes inherited from Code::Object
#raw
Class Method Summary
collapse
Instance Method Summary
collapse
#<=>, #==, call, #code_and_operator, code_and_operator, #code_different, code_different, code_equal_equal, #code_equal_equal, code_equal_equal_equal, #code_equal_equal_equal, code_exclamation_point, #code_exclamation_point, code_exclusive_range, #code_exclusive_range, #code_inclusive_range, code_inclusive_range, code_new, code_or_operator, #code_or_operator, code_self, #code_self, #code_to_string, code_to_string, falsy?, #falsy?, #hash, inspect, maybe, multi_fetch, #multi_fetch, repeat, #sig, sig, #to_json, to_s, truthy?, |
Constructor Details
#initialize(*args, **_kargs, &_block) ⇒ Boolean
Returns a new instance of Boolean.
6
7
8
9
10
11
|
# File 'lib/code/object/boolean.rb', line 6
def initialize(*args, **_kargs, &_block)
raw = args.first || Nothing.new
raw = raw.raw if raw.is_a?(Object)
@raw = !!raw
super
end
|
Class Method Details
13
14
15
|
# File 'lib/code/object/boolean.rb', line 13
def self.name
"Boolean"
end
|
Instance Method Details
65
66
67
|
# File 'lib/code/object/boolean.rb', line 65
def as_json(...)
raw.as_json(...)
end
|
#call(**args) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/code/object/boolean.rb', line 17
def call(**args)
operator = args.fetch(:operator, nil)
arguments = args.fetch(:arguments, [])
value = arguments.first&.value
case operator.to_s
when "&", "bitwise_and"
sig(args) { Boolean }
code_bitwise_and(value)
when "^", "bitwise_xor"
sig(args) { Boolean }
code_bitwise_xor(value)
when "|", "bitwise_or"
sig(args) { Boolean }
code_bitwise_or(value)
else
super
end
end
|
#code_bitwise_and(value) ⇒ Object
37
38
39
|
# File 'lib/code/object/boolean.rb', line 37
def code_bitwise_and(value)
Boolean.new(raw & value.raw)
end
|
#code_bitwise_or(value) ⇒ Object
41
42
43
|
# File 'lib/code/object/boolean.rb', line 41
def code_bitwise_or(value)
Boolean.new(raw | value.raw)
end
|
#code_bitwise_xor(value) ⇒ Object
45
46
47
|
# File 'lib/code/object/boolean.rb', line 45
def code_bitwise_xor(value)
Boolean.new(raw ^ value.raw)
end
|
49
50
51
|
# File 'lib/code/object/boolean.rb', line 49
def inspect
to_s
end
|
53
54
55
|
# File 'lib/code/object/boolean.rb', line 53
def succ
Boolean.new(!raw)
end
|
57
58
59
|
# File 'lib/code/object/boolean.rb', line 57
def to_s
raw.to_s
end
|
61
62
63
|
# File 'lib/code/object/boolean.rb', line 61
def truthy?
raw
end
|