Slowly… I believe #each_slice was added later as well. Oh well.
Can’t you just upgrade your Ruby version? That seems a much better
option than trying to retrofit all the new behavior on the old
version.
Slowly… I believe #each_slice was added later as well. Oh well.
Can’t you just upgrade your Ruby version? That seems a much better
option than trying to retrofit all the new behavior on the old
version.
not exist in 1.8.2 (which is ancient btw - I cannot remember having
used it).
Kind regards
robert
So there is no way i can do that in 1.8.2 ?
You can write Enumerator yourself. It isn’t too hard
Enum = Struct.new :inst, :args do
include Enumerable
def each(&b)
inst.send(*args, &b)
self
end
end
class Object
def to_enum(*a)
Enum.new(self, a)
end
end
Kind regards
robert
Thanks again Robert but (there is always a BUT)…
I copy paste the code you gave me
Enum = Struct.new :inst, :args do
include Enumerable
def each(&b)
inst.send(*args, &b)
self
end
end
class Object
def to_enum(*a)
Enum.new(self, a)
end
end
File.to_enum(:foreach, “/etc/raddb/users”).each_slice 4 do
|name, ip, dump, table|
puts name.strip!
puts ip.strip!
puts table.strip!
end
Slowly… I believe #each_slice was added later as well. Oh well.
Can’t you just upgrade your Ruby version? That seems a much better
option than trying to retrofit all the new behavior on the old
version.
Kind regards
robert
I’ll try to upgrade.
Unfortunately, the provider doesn’t have a newer version of ruby :s