method

%

Importance_2
Ruby latest stable (v2_5_5) - 0 notes - Class: Range
  • 1_8_6_287
  • 1_8_7_72
  • 1_8_7_330
  • 1_9_1_378
  • 1_9_2_180
  • 1_9_3_125
  • 1_9_3_392
  • 2_1_10
  • 2_2_9
  • 2_4_6
  • 2_5_5
  • 2_6_3 (0)
  • What's this?

Method not available on this version

This method is only available on newer versions. The first available version of the method is shown here.

%(p1) public

Iterates over the range, passing each nth element to the block. If begin and end are numeric, n is added for each iteration. Otherwise step invokes succ to iterate through range elements.

If no block is given, an enumerator is returned instead. Especially, the enumerator is an Enumerator::ArithmeticSequence if begin and end of the range are numeric.

range = Xs.new(1)..Xs.new(10)
range.step(2) {|x| puts x}
puts
range.step(3) {|x| puts x}

produces:

 1 x
 3 xxx
 5 xxxxx
 7 xxxxxxx
 9 xxxxxxxxx

 1 x
 4 xxxx
 7 xxxxxxx
10 xxxxxxxxxx

See Range for the definition of class Xs.

Show source
Register or log in to add new notes.