Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/lisp/interpreter/core/object.rb
Overview
redefine method in Object class
Instance Method Summary collapse
- #boolean? ⇒ Boolean
- #character? ⇒ Boolean
- #list? ⇒ Boolean
- #number? ⇒ Boolean
- #pair? ⇒ Boolean
- #quote? ⇒ Boolean
- #string? ⇒ Boolean
- #to_num ⇒ Object
- #type ⇒ Object
Instance Method Details
#boolean? ⇒ Boolean
38 39 40 |
# File 'lib/lisp/interpreter/core/object.rb', line 38 def boolean? ['#t', '#f'].include? self end |
#character? ⇒ Boolean
12 13 14 15 |
# File 'lib/lisp/interpreter/core/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
22 23 24 25 |
# File 'lib/lisp/interpreter/core/object.rb', line 22 def list? return false if size < 3 check_for_list end |
#number? ⇒ Boolean
3 4 5 |
# File 'lib/lisp/interpreter/core/object.rb', line 3 def number? to_f.to_s == to_s || to_i.to_s == to_s end |
#pair? ⇒ Boolean
27 28 29 30 31 32 |
# File 'lib/lisp/interpreter/core/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
34 35 36 |
# File 'lib/lisp/interpreter/core/object.rb', line 34 def quote? start_with? '\'' end |
#string? ⇒ Boolean
17 18 19 20 |
# File 'lib/lisp/interpreter/core/object.rb', line 17 def string? return false unless self.class == String (start_with? '"') && (end_with? '"') && (size != 1) end |
#to_num ⇒ Object
7 8 9 10 |
# File 'lib/lisp/interpreter/core/object.rb', line 7 def to_num return to_f if to_f.to_s == to_s to_i if to_i.to_s == to_s end |
#type ⇒ Object
42 43 44 45 |
# File 'lib/lisp/interpreter/core/object.rb', line 42 def type fns = %w[list pair string number character boolean quote] fns.each { |t| return '<' + t + '>' if send t + '?' } end |