Class: Rust::Sequence
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.
- #step(step) ⇒ Object
- #to_a ⇒ Object
- #to_R ⇒ Object
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
#max ⇒ Object (readonly)
Returns the value of attribute max.
485 486 487 |
# File 'lib/rust-core.rb', line 485 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
484 485 486 |
# File 'lib/rust-core.rb', line 484 def min @min end |
Instance Method Details
#each ⇒ Object
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_a ⇒ Object
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_R ⇒ Object
511 512 513 |
# File 'lib/rust-core.rb', line 511 def to_R "seq(from=#@min, to=#@max, by=#@step)" end |