Class: Rust::Sequence

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Sequence.



487
488
489
490
491
# File 'lib/rust-core.rb', line 487

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

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



485
486
487
# File 'lib/rust-core.rb', line 485

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



484
485
486
# File 'lib/rust-core.rb', line 484

def min
  @min
end

Instance Method Details

#eachObject



497
498
499
500
501
# File 'lib/rust-core.rb', line 497

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

#step(step) ⇒ Object



493
494
495
# File 'lib/rust-core.rb', line 493

def step(step)
    @step = step
end

#to_aObject



503
504
505
506
507
508
509
# File 'lib/rust-core.rb', line 503

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

#to_RObject



511
512
513
# File 'lib/rust-core.rb', line 511

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