Add method to Range : Range Extension « Range « Ruby






Add method to Range


class Range
  def each_slow
    x = self.begin
    while x <= self.end
      yield x
      x = x.succ
    end
  end
end

(1..3).each_slow {|x| puts x}
# 1
# 2
# 3

 








Related examples in the same category

1.Extend Range to add new method