Class: Code::Object::Boolean
Instance Attribute Summary
Attributes inherited from Code::Object
#raw
Instance Method Summary
collapse
#<=>, #==, as_json, #as_json, call, #code_and_operator, code_and_operator, #code_as_json, code_as_json, 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_json, code_to_json, falsy?, #falsy?, #hash, inspect, maybe, multi_fetch, #multi_fetch, #nothing?, nothing?, repeat, sig, #sig, #succ, to_json, #to_json, to_s, truthy?, |
Constructor Details
#initialize(*args, **_kargs) ⇒ Boolean
Returns a new instance of Boolean.
6
7
8
9
10
|
# File 'lib/code/object/boolean.rb', line 6
def initialize(*args, **_kargs, &)
raw = args.first || Nothing.new
raw = raw.raw if raw.is_a?(Object)
@raw = !!raw
end
|
Instance Method Details
#call(**args) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/code/object/boolean.rb', line 12
def call(**args)
operator = args.fetch(:operator, nil)
arguments = args.fetch(:arguments, List.new)
value = arguments.code_first
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
32
33
34
|
# File 'lib/code/object/boolean.rb', line 32
def code_bitwise_and(value)
Boolean.new(raw & value.raw)
end
|
#code_bitwise_or(value) ⇒ Object
36
37
38
|
# File 'lib/code/object/boolean.rb', line 36
def code_bitwise_or(value)
Boolean.new(raw | value.raw)
end
|
#code_bitwise_xor(value) ⇒ Object
40
41
42
|
# File 'lib/code/object/boolean.rb', line 40
def code_bitwise_xor(value)
Boolean.new(raw ^ value.raw)
end
|
44
45
46
|
# File 'lib/code/object/boolean.rb', line 44
def truthy?
raw
end
|