Class: Rust::Sequence
- Inherits:
-
RustDatatype
- Object
- RustDatatype
- Rust::Sequence
- Defined in:
- lib/rust/core/types/utils.rb
Overview
Represents a sequence of values in R (through a call to the seq function).
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
Class Method Summary collapse
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(min, max, step = 1) ⇒ Sequence
constructor
Creates a new sequence from
min
tomax
with a givenstep
(default = 1). - #load_in_r_as(variable_name) ⇒ Object
-
#step=(step) ⇒ Object
(also: #step)
Sets the step to
step
. - #to_a ⇒ Object
- #to_R ⇒ Object
Methods inherited from RustDatatype
pull_priority, pull_variable, #r_hash, #r_mirror, #r_mirror_to
Constructor Details
#initialize(min, max, step = 1) ⇒ Sequence
Creates a new sequence from min
to max
with a given step
(default = 1).
19 20 21 22 23 |
# File 'lib/rust/core/types/utils.rb', line 19 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.
10 11 12 |
# File 'lib/rust/core/types/utils.rb', line 10 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
9 10 11 |
# File 'lib/rust/core/types/utils.rb', line 9 def min @min end |
Class Method Details
.can_pull?(type, klass) ⇒ Boolean
12 13 14 |
# File 'lib/rust/core/types/utils.rb', line 12 def self.can_pull?(type, klass) return false end |
Instance Method Details
#each ⇒ Object
35 36 37 38 39 |
# File 'lib/rust/core/types/utils.rb', line 35 def each (@min..@max).step(@step) do |v| yield v end end |
#load_in_r_as(variable_name) ⇒ Object
53 54 55 |
# File 'lib/rust/core/types/utils.rb', line 53 def load_in_r_as(variable_name) Rust._eval("#{variable_name} <- #{self.to_R}") end |
#step=(step) ⇒ Object Also known as: step
Sets the step to step
.
28 29 30 31 32 |
# File 'lib/rust/core/types/utils.rb', line 28 def step=(step) @step = step return self end |
#to_a ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/rust/core/types/utils.rb', line 41 def to_a result = [] self.each do |v| result << v end return result end |
#to_R ⇒ Object
49 50 51 |
# File 'lib/rust/core/types/utils.rb', line 49 def to_R "seq(from=#@min, to=#@max, by=#@step)" end |