Class: Rust::Sequence

Inherits:
RustDatatype show all
Defined in:
lib/rust-core.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RustDatatype

pull_variable

Constructor Details

#initialize(min, max, step = 1) ⇒ Sequence

Returns a new instance of Sequence.



632
633
634
635
636
# File 'lib/rust-core.rb', line 632

def initialize(min, max, step=1)
    @min = min
    @max = max
    @step = step
end

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



630
631
632
# File 'lib/rust-core.rb', line 630

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



629
630
631
# File 'lib/rust-core.rb', line 629

def min
  @min
end

Instance Method Details

#eachObject



642
643
644
645
646
# File 'lib/rust-core.rb', line 642

def each
    (@min..@max).step(@step) do |v|
        yield v
    end
end

#load_in_r_as(variable_name) ⇒ Object



660
661
662
# File 'lib/rust-core.rb', line 660

def load_in_r_as(variable_name)
    Rust._eval("#{variable_name} <- #{self.to_R}")
end

#step(step) ⇒ Object



638
639
640
# File 'lib/rust-core.rb', line 638

def step(step)
    @step = step
end

#to_aObject



648
649
650
651
652
653
654
# File 'lib/rust-core.rb', line 648

def to_a
    result = []
    self.each do |v|
        result << v
    end
    return result
end

#to_RObject



656
657
658
# File 'lib/rust-core.rb', line 656

def to_R
    "seq(from=#@min, to=#@max, by=#@step)"
end