class Object
Object
class
Constants
- FALSE
- TRUE
Public Instance Methods
boolean?()
click to toggle source
# File lib/lisp/interpreter/core/object.rb, line 41 def boolean? self == TRUE || self == FALSE end
character?()
click to toggle source
# File lib/lisp/interpreter/core/object.rb, line 15 def character? return true if self == '#\space' (start_with? '#\\') && (('a'..'z').to_a.include? self[2]) && size == 3 end
list?()
click to toggle source
# File lib/lisp/interpreter/core/object.rb, line 25 def list? return false if size < 3 check_for_list end
number?()
click to toggle source
# File lib/lisp/interpreter/core/object.rb, line 6 def number? match(/^[\+\-]?\d*\.?\d+(?:[Ee][\+\-]?\d+)?$/) end
pair?()
click to toggle source
# File lib/lisp/interpreter/core/object.rb, line 30 def pair? res = object_split if is_a? String res = to_a if is_a? Array return true if res[-3] == '.' list? && !res[2..-2].empty? end
quote?()
click to toggle source
# File lib/lisp/interpreter/core/object.rb, line 37 def quote? start_with? '\'' end
string?()
click to toggle source
# File lib/lisp/interpreter/core/object.rb, line 20 def string? return false unless self.class == String (start_with? '"') && (end_with? '"') && (size != 1) end
to_char()
click to toggle source
# File lib/lisp/interpreter/core/object.rb, line 50 def to_char '#\\' + (self == ' ' ? 'space' : self) end
to_num()
click to toggle source
# File lib/lisp/interpreter/core/object.rb, line 10 def to_num return to_f if to_s.include? '.' to_i end
type()
click to toggle source
# File lib/lisp/interpreter/core/object.rb, line 45 def type fns = %w[list pair string number character boolean quote] fns.each { |t| return '<' + t + '>' if send t + '?' } end
Private Instance Methods
check_for_list()
click to toggle source
# File lib/lisp/interpreter/core/object.rb, line 62 def check_for_list res = to_a if is_a? Array res = object_split if is_a? String res[0..1].join == '\'(' && res[-1] == ')' && res[-3] != '.' end
object_split()
click to toggle source
# File lib/lisp/interpreter/core/object.rb, line 56 def object_split result = to_s.split(/(\(|\)|\.)|\ /) result.delete('') result end