Class: Object

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

Overview

redefine method in Object class

Instance Method Summary collapse

Instance Method Details

#boolean?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/lisp/interpreter/object.rb', line 39

def boolean?
  ['#t', '#f'].include? self
end

#character?Boolean

Returns:

  • (Boolean)


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

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

#list?Boolean

Returns:

  • (Boolean)


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

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)


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

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)


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

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

#string?Boolean

Returns:

  • (Boolean)


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

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

#typeObject



43
44
45
46
47
48
49
50
51
# File 'lib/lisp/interpreter/object.rb', line 43

def type
  return 'list' if list?
  return 'pair' if pair?
  return 'string' if string?
  return 'number' if number?
  return 'character' if character?
  return 'boolean' if boolean?
  'quote'
end