Some noob questions

2010/2/12 John Y. [email protected]:

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

:slight_smile:

Kind regards

robert

Robert K. wrote:

2010/2/11 John Y. [email protected]:

“foreach” since you should do “foreach” on … er … each line in the
� � � �puts name.strip!
� � � �from ./test.rb:5

Maybe I haven’t the full ruby because it’s a small linux…

Oooops! Sorry for the wrong advice. Either that or Enumerator did
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 ?

2010/2/12 John Y. [email protected]:

Thanks again Robert but (there is always a BUT)…

I copy paste the code you gave me

I think we progress…

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

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.

Robert K. wrote:

2010/2/12 John Y. [email protected]:

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

:slight_smile:

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

./test.rb:31: undefined method `each_slice’ for #<struct Enum inst=File,
args=[:foreach, “/etc/raddb/users”]> (NoMethodError)

I think we progress…

2010/2/15 John Y. [email protected]:

robert

I’ll try to upgrade.

Unfortunately, the provider doesn’t have a newer version of ruby :s

module Enumerable
def each_slice(num)
sl = []

each do |x|
  sl << x

  if sl.size == num
    yield sl
    sl = []
  end
end

yield sl unless sl.empty?

self

end
end

Kind regards

robert

John Y. wrote:

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

John Y. wrote:

You are awesome !

Robert, indeed, is. Donations can be sent to
[email protected] for attempts at cloning his awesomeness.

You are awesome !