25 lines
250 B
Ruby
25 lines
250 B
Ruby
|
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
|
||
|
|