Class: Lisp::Boolean

Inherits:
Atom show all
Defined in:
lib/rubylisp/boolean.rb

Instance Attribute Summary

Attributes inherited from Atom

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Atom

#alist?, #all?, #apply_to, #car, #cdr, #character?, #class?, #copy, #doc, #eq?, #evaluate, #frame?, #function?, #length, #lisp_object?, #list?, #macro?, #negative?, #number?, #object?, #pair?, #positive?, #primitive?, #print_string, #quoted, #set!, #special?, #string?, #symbol?, #vector?, #zero?

Constructor Details

#initialize(b) ⇒ Boolean

Returns a new instance of Boolean.



16
17
18
# File 'lib/rubylisp/boolean.rb', line 16

def initialize(b)
  @value = b
end

Class Method Details

.FALSEObject



8
9
10
# File 'lib/rubylisp/boolean.rb', line 8

def self.FALSE
  @false_constant ||= Boolean.new(false)
end

.TRUEObject



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

def self.TRUE
  @true_constant ||= Boolean.new(true)
end

.with_value(b) ⇒ Object



12
13
14
# File 'lib/rubylisp/boolean.rb', line 12

def self.with_value(b)
  b ? self.TRUE : self.FALSE
end

Instance Method Details

#boolean?Boolean

Returns:



24
25
26
# File 'lib/rubylisp/boolean.rb', line 24

def boolean?
  true
end

#false?Boolean

Returns:



37
38
39
# File 'lib/rubylisp/boolean.rb', line 37

def false?
  !@value
end

#negateObject



41
42
43
# File 'lib/rubylisp/boolean.rb', line 41

def negate
  Lisp::Boolean.with_value(!@value)
end

#to_sObject



28
29
30
31
# File 'lib/rubylisp/boolean.rb', line 28

def to_s
  return "#t" if @value
  "#f"
end

#true?Boolean

Returns:



33
34
35
# File 'lib/rubylisp/boolean.rb', line 33

def true?
  @value
end

#typeObject



20
21
22
# File 'lib/rubylisp/boolean.rb', line 20

def type
  :boolean
end