Class: Object

Inherits:
BasicObject
Defined in:
lib/lisp/interpreter/object.rb

Overview

redefine method in Object class

Instance Method Summary collapse

Instance Method Details

#character?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/lisp/interpreter/object.rb', line 12

def character?
  (start_with? '#\\') && (('a'..'z').to_a.include? self[2]) && size == 3
end

#list?Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/lisp/interpreter/object.rb', line 21

def list?
  return false if size < 3
  check_for_list
end

#number?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/lisp/interpreter/object.rb', line 3

def number?
  to_f.to_s == to_s || to_i.to_s == to_s
end

#pair?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
# File 'lib/lisp/interpreter/object.rb', line 26

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?Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/lisp/interpreter/object.rb', line 33

def quote?
  return true if start_with? '\''
  false
end

#string?Boolean

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/lisp/interpreter/object.rb', line 16

def string?
  return false unless self.class == String
  (start_with? '"') && (end_with? '"') && (size != 1)
end

#to_numObject



7
8
9
10
# File 'lib/lisp/interpreter/object.rb', line 7

def to_num
  return to_f if to_f.to_s == to_s
  return to_i if to_i.to_s == to_s
end