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

#all?, #apply_to, #car, #cdr, #character?, #class?, #copy, #doc, #environment?, #eof_object?, #eq?, #equal?, #eqv?, #evaluate, #frame?, #function?, #length, #lisp_object?, #list?, #macro?, #negative?, #number?, #object?, #pair?, #port?, #positive?, #primitive?, #print_string, #quoted, #set!, #set_location, #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 ||= Lisp::Boolean.new(false)
end

.TRUEObject



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

def self.TRUE
  @true_constant ||= Lisp::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:



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

def false?
  !@value
end

#negateObject



44
45
46
# File 'lib/rubylisp/boolean.rb', line 44

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

#to_sObject



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

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

#true?Boolean

Returns:



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

def true?
  @value
end

#typeObject



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

def type
  :boolean
end