cours0708/P5B/ruby/exercices/class_Integer.rb

25 lines
250 B
Ruby
Raw Normal View History

2008-11-25 21:11:16 +00:00
class Impairs
def initialize(n)
@cardinal = n
end
def each
i = 1
@cardinal.times do
yield i
i = i +2
end
end
end
class Integer
def premiers_impairs
Impairs.new(self)
end
end
3.premiers_impairs.each do | i |
puts i.to_s
end