class CharIterator
def initialize(str)
@str = str
@idx = 0
end
def next
begin
@str[@idx]
ensure
@idx += 1
end
end
def has_next?
@idx < @str.length
end
end
class CharSet
def initialize(str)
@str = str
end
def iterator
CharIterator.new(@str)
end
end
#### main ####
char_set = CharSet.new('abcdefghijklmn')
iterator = char_set.iterator
while iterator.has_next?
puts iterator.next
end
Y2xhc3MgQ2hhckl0ZXJhdG9yCiAgZGVmIGluaXRpYWxpemUoc3RyKQogICAgQHN0ciA9IHN0cgogICAgQGlkeCA9IDAKICBlbmQKCiAgZGVmIG5leHQKICAgIGJlZ2luCiAgICAgIEBzdHJbQGlkeF0KICAgIGVuc3VyZQogICAgICBAaWR4ICs9IDEKICAgIGVuZAogIGVuZAoKICBkZWYgaGFzX25leHQ/CiAgICBAaWR4IDwgQHN0ci5sZW5ndGgKICBlbmQKZW5kCgpjbGFzcyBDaGFyU2V0CiAgZGVmIGluaXRpYWxpemUoc3RyKQogICAgQHN0ciA9IHN0cgogIGVuZAoKICBkZWYgaXRlcmF0b3IKICAgIENoYXJJdGVyYXRvci5uZXcoQHN0cikKICBlbmQKZW5kCgojIyMjIG1haW4gIyMjIwoKY2hhcl9zZXQgPSBDaGFyU2V0Lm5ldygnYWJjZGVmZ2hpamtsbW4nKQppdGVyYXRvciA9IGNoYXJfc2V0Lml0ZXJhdG9yCgp3aGlsZSBpdGVyYXRvci5oYXNfbmV4dD8KICBwdXRzIGl0ZXJhdG9yLm5leHQKZW5k