Class: Array
Overview
The normal Array class is modified so that an array can be converted to either Relisp::List or Relisp::Vector.
Direct Known Subclasses
Constant Summary collapse
Class Method Summary collapse
- .default_elisp_type ⇒ Object
-
.default_elisp_type=(type) ⇒ Object
Set the elisp type that ruby arrays are converted to by default.
-
.from_elisp(object) ⇒ Object
Converts either a ‘cons’ or ‘vector’ to a ruby array.
Instance Method Summary collapse
-
#elisp_type ⇒ Object
The elisp type that this array will be converted to by to_elisp.
- #elisp_type=(type) ⇒ Object
- #to_elisp ⇒ Object
Class Method Details
.default_elisp_type ⇒ Object
449 450 451 |
# File 'lib/relisp/type_conversion/programming_types.rb', line 449 def self.default_elisp_type @@default_elisp_type end |
.default_elisp_type=(type) ⇒ Object
Set the elisp type that ruby arrays are converted to by default.
441 442 443 444 445 446 447 |
# File 'lib/relisp/type_conversion/programming_types.rb', line 441 def self.default_elisp_type=(type) unless type.ancestors.include?(Array) raise ArgumentError, "#{type} is not a kind of Array" end @@default_elisp_type = type end |
.from_elisp(object) ⇒ Object
Converts either a ‘cons’ or ‘vector’ to a ruby array.
428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/relisp/type_conversion/programming_types.rb', line 428 def self.from_elisp(object) object_variable = object[:slave].get_permanent_variable(object[:variable]) size = object[:slave].elisp_eval( "(length #{object_variable})" ) object_array = new size.times do |i| object_array << object[:slave].elisp_eval( "(elt #{object_variable} #{i.to_elisp})" ) end object[:slave].elisp_exec( "(makunbound #{object_variable.to_elisp})" ) return object_array end |
Instance Method Details
#elisp_type ⇒ Object
The elisp type that this array will be converted to by to_elisp.
454 455 456 457 |
# File 'lib/relisp/type_conversion/programming_types.rb', line 454 def elisp_type @elisp_type = nil unless defined?(@elisp_type) #to avoid uninitialized warning @elisp_type || @@default_elisp_type end |
#elisp_type=(type) ⇒ Object
459 460 461 462 463 464 465 |
# File 'lib/relisp/type_conversion/programming_types.rb', line 459 def elisp_type=(type) unless type.ancestors.include?(Array) raise ArgumentError, "#{type} is not a kind of Array" end @elisp_type = type end |
#to_elisp ⇒ Object
467 468 469 |
# File 'lib/relisp/type_conversion/programming_types.rb', line 467 def to_elisp elisp_type.new(self).to_elisp end |