Java. It’s just a method that calls yield every time it generates a new value. Ruby already provides a lot of useful iterators: each, map, inject, etc...
x } You can look inside objects [1,2,3].methods [1,2,3].respond_to?(:to_s) [1,2,3].kind_of?(Hash) You can invoke methods without knowing their names a = [1,2,3] a.send(a.private_methods.first.to_sym) You can know about the runtime environment Fixnum.class_variables print File.read(__FILE__)
"eat"].each do |baby_action| define_method(baby_action) do "Of course, babies #{baby_action}" end end def method_missing(name, *args, &blk) "Nope, babies don’t #{name}" end end