Generator based on regualr expression : Generator « Development « Ruby






Generator based on regualr expression

require 'generator'
l = ["junk1", 1, "junk2", 2, "junk3", "junk4", 3, "junk5"]

g = Generator.new { |g| l.each { |e| g.yield e unless e =~ /^junk/ } }
g.next                                            # => 1
g.next                                            # => 2
g.next                                            # => 3

 








Related examples in the same category

1.Generate from array