Class: Float

Inherits:
Object
  • Object
show all
Defined in:
mrblib/numeric.rb

Instance Method Summary collapse

Instance Method Details

#step(num = nil, step = 1, &block) ⇒ Object

Raises:



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'mrblib/numeric.rb', line 135

def step(num=nil, step=1, &block)
  raise ArgumentError, "step can't be 0" if step == 0
  return to_enum(:step, num, step) unless block

  i = self
  if num == self || step.infinite?
    block.call(i) if step > 0 && i <= (num||i) || step < 0 && i >= (num||-i)
  elsif num == nil
    while true
      block.call(i)
      i += step
    end
  elsif step > 0
    while i <= num
      block.call(i)
      i += step
    end
  else
    while i >= num
      block.call(i)
      i += step
    end
  end
  self
end