Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/lisp/interpreter/core/object.rb
Overview
Object class
Instance Method Summary collapse
- #boolean? ⇒ Boolean
- #character? ⇒ Boolean
- #list? ⇒ Boolean
- #number? ⇒ Boolean
- #pair? ⇒ Boolean
- #quote? ⇒ Boolean
- #string? ⇒ Boolean
- #to_char ⇒ Object
- #to_num ⇒ Object
- #type ⇒ Object
Instance Method Details
#boolean? ⇒ Boolean
41 42 43 |
# File 'lib/lisp/interpreter/core/object.rb', line 41 def boolean? ['#t', '#f'].include? self end |
#character? ⇒ Boolean
15 16 17 18 |
# 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? ⇒ Boolean
25 26 27 28 |
# File 'lib/lisp/interpreter/core/object.rb', line 25 def list? return false if size < 3 check_for_list end |
#number? ⇒ Boolean
6 7 8 |
# File 'lib/lisp/interpreter/core/object.rb', line 6 def number? match(/^[\+\-]?\d*\.?\d+(?:[Ee][\+\-]?\d+)?$/) end |
#pair? ⇒ Boolean
30 31 32 33 34 35 |
# 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? ⇒ Boolean
37 38 39 |
# File 'lib/lisp/interpreter/core/object.rb', line 37 def quote? start_with? '\'' end |
#string? ⇒ Boolean
20 21 22 23 |
# 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 ⇒ Object
50 51 52 |
# File 'lib/lisp/interpreter/core/object.rb', line 50 def to_char '#\\' + (self == ' ' ? 'space' : self) end |
#to_num ⇒ Object
10 11 12 13 |
# File 'lib/lisp/interpreter/core/object.rb', line 10 def to_num return to_f if to_s.include? '.' to_i end |
#type ⇒ Object
45 46 47 48 |
# 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 |