Class: Rust::Sequence
- Inherits:
-
RustDatatype
- Object
- RustDatatype
- Rust::Sequence
- Defined in:
- lib/rust-core.rb
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(min, max, step = 1) ⇒ Sequence
constructor
A new instance of Sequence.
- #load_in_r_as(variable_name) ⇒ Object
- #step(step) ⇒ Object
- #to_a ⇒ Object
- #to_R ⇒ Object
Methods inherited from RustDatatype
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
#max ⇒ Object (readonly)
Returns the value of attribute max.
630 631 632 |
# File 'lib/rust-core.rb', line 630 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
629 630 631 |
# File 'lib/rust-core.rb', line 629 def min @min end |
Instance Method Details
#each ⇒ Object
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_a ⇒ Object
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_R ⇒ Object
656 657 658 |
# File 'lib/rust-core.rb', line 656 def to_R "seq(from=#@min, to=#@max, by=#@step)" end |