Class: Rust::Sequence

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RustDatatype

pull_priority, pull_variable, #r_hash, #r_mirror, #r_mirror_to

Constructor Details

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

Returns a new instance of Sequence.



12
13
14
15
16
# File 'lib/rust/core/types/utils.rb', line 12

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

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



6
7
8
# File 'lib/rust/core/types/utils.rb', line 6

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



5
6
7
# File 'lib/rust/core/types/utils.rb', line 5

def min
  @min
end

Class Method Details

.can_pull?(type, klass) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/rust/core/types/utils.rb', line 8

def self.can_pull?(type, klass)
    return false
end

Instance Method Details

#eachObject



22
23
24
25
26
# File 'lib/rust/core/types/utils.rb', line 22

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

#load_in_r_as(variable_name) ⇒ Object



40
41
42
# File 'lib/rust/core/types/utils.rb', line 40

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

#step(step) ⇒ Object



18
19
20
# File 'lib/rust/core/types/utils.rb', line 18

def step(step)
    @step = step
end

#to_aObject



28
29
30
31
32
33
34
# File 'lib/rust/core/types/utils.rb', line 28

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

#to_RObject



36
37
38
# File 'lib/rust/core/types/utils.rb', line 36

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