Class: Keisan::AST::Boolean

Inherits:
ConstantLiteral show all
Defined in:
lib/keisan/ast/boolean.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ConstantLiteral

#==, #evaluate, #to_s

Methods inherited from Node

#%, #&, #*, #**, #+, #+@, #-, #-@, #/, #<, #<=, #>, #>=, #^, #coerce, #deep_dup, #differentiate, #evaluate, #evaluate_assignments, #evaluated, #false?, #replace, #simplified, #simplify, #to_cell, #to_node, #unbound_functions, #unbound_variables, #well_defined?, #|, #~

Constructor Details

#initialize(bool) ⇒ Boolean

Returns a new instance of Boolean.



6
7
8
# File 'lib/keisan/ast/boolean.rb', line 6

def initialize(bool)
  @bool = bool
end

Instance Attribute Details

#boolObject (readonly)

Returns the value of attribute bool.



4
5
6
# File 'lib/keisan/ast/boolean.rb', line 4

def bool
  @bool
end

Instance Method Details

#!Object



18
19
20
# File 'lib/keisan/ast/boolean.rb', line 18

def !
  Boolean.new(!bool)
end

#and(other) ⇒ Object



22
23
24
25
# File 'lib/keisan/ast/boolean.rb', line 22

def and(other)
  other = other.to_node
  other.is_a?(Boolean) ? Boolean.new(bool && other.bool) : super
end

#equal(other) ⇒ Object



32
33
34
35
# File 'lib/keisan/ast/boolean.rb', line 32

def equal(other)
  other = other.to_node
  other.is_a?(Boolean) ? Boolean.new(value == other.value) : super
end

#not_equal(other) ⇒ Object



37
38
39
40
# File 'lib/keisan/ast/boolean.rb', line 37

def not_equal(other)
  other = other.to_node
  other.is_a?(Boolean) ? Boolean.new(value != other.value) : super
end

#or(other) ⇒ Object



27
28
29
30
# File 'lib/keisan/ast/boolean.rb', line 27

def or(other)
  other = other.to_node
  other.is_a?(Boolean) ? Boolean.new(bool || other.bool) : super
end

#true?Boolean

Returns:



14
15
16
# File 'lib/keisan/ast/boolean.rb', line 14

def true?
  false
end

#value(context = nil) ⇒ Object



10
11
12
# File 'lib/keisan/ast/boolean.rb', line 10

def value(context = nil)
  bool
end