Class: Rserve::Rlist
- Inherits:
-
Array
- Object
- Array
- Rserve::Rlist
- Includes:
- WithNames
- Defined in:
- lib/rserve/rlist.rb
Instance Attribute Summary
Attributes included from WithNames
Instance Method Summary collapse
- #==(o) ⇒ Object
-
#data ⇒ Object
Returns the data, as REXP.
-
#initialize(data = nil, n = nil) ⇒ Rlist
constructor
A new instance of Rlist.
- #keys ⇒ Object
-
#to_a ⇒ Object
Returns the data without names, as Ruby objects.
-
#to_ruby ⇒ Object
Returns an Array with module WithNames included * Unnamed list: returns an Array * Named List: returns a Hash.
- #to_s ⇒ Object
Methods included from WithNames
#[], #[]=, #__add, #clear, #delete_at, #has_name?, #inspect, #key_at, #named?, #pop, #pretty_print, #push, #put, #reverse!, #shift, #slice
Constructor Details
#initialize(data = nil, n = nil) ⇒ Rlist
Returns a new instance of Rlist.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rserve/rlist.rb', line 4 def initialize(data=nil, n=nil) @names=nil if data.nil? super() else case data when Array super(data) when Numeric super([data]) else raise ArgumentError end end if n @names=Array.new(size) n.each_index {|i| @names[i]=n[i]} if n.respond_to? :each_index end end |
Instance Method Details
#==(o) ⇒ Object
34 35 36 37 |
# File 'lib/rserve/rlist.rb', line 34 def ==(o) #p "Comparing #{self.inspect} with #{o.inspect} gives #{o.is_a? Rlist and self.data==o.data and self.names==o.names}" o.is_a? Rlist and self.data==o.data and self.names==o.names end |
#data ⇒ Object
Returns the data, as REXP
31 32 33 |
# File 'lib/rserve/rlist.rb', line 31 def data self.map {|d| d} end |
#keys ⇒ Object
23 24 25 |
# File 'lib/rserve/rlist.rb', line 23 def keys @names end |
#to_a ⇒ Object
Returns the data without names, as Ruby objects
27 28 29 |
# File 'lib/rserve/rlist.rb', line 27 def to_a self.map {|d| d.to_ruby} end |
#to_ruby ⇒ Object
Returns an Array with module WithNames included
-
Unnamed list: returns an Array
-
Named List: returns a Hash. Every element without explicit name receive as key the number of element, 1-based
48 49 50 51 52 53 |
# File 'lib/rserve/rlist.rb', line 48 def to_ruby data=to_a data.extend WithNames data.names=@names data end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/rserve/rlist.rb', line 38 def to_s super+"[#{size}]" end |