class Pointer
def each_element(size)
size.times do |i|
yield self[i]
end
self
end
end
p = Pointer.new(:string, 5)
p[0] = "foo"
p[1] = "bar"
p[2] = "baz"
enum = p.to_enum(:each_element, 3)
enum.each do |item|
p item
end
enum.each_with_index do |item, i|
p "#{i} : #{item}"
end
p.each_element(3) do |item|
p item
end