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
403 404 405 |
# File 'lib/relisp/type_conversion/programming_types.rb', line 403 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.
395 396 397 398 399 400 401 |
# File 'lib/relisp/type_conversion/programming_types.rb', line 395 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.
382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/relisp/type_conversion/programming_types.rb', line 382 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.
408 409 410 411 |
# File 'lib/relisp/type_conversion/programming_types.rb', line 408 def elisp_type @elisp_type = nil unless defined?(@elisp_type) #to avoid uninitialized warning @elisp_type || @@default_elisp_type end |
#elisp_type=(type) ⇒ Object
413 414 415 416 417 418 419 |
# File 'lib/relisp/type_conversion/programming_types.rb', line 413 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
421 422 423 |
# File 'lib/relisp/type_conversion/programming_types.rb', line 421 def to_elisp elisp_type.new(self).to_elisp end |