The Enumerator object provides some common methods for enumerations - next , each , each_with_index , rewind , etc.
You get an Enumerator object here because gsub extremely flexible:
gsub(pattern, replacement) → new_str gsub(pattern, hash) → new_str gsub(pattern) {|match| block } → new_str gsub(pattern) → enumerator
In the first three cases, the replacement can be performed immediately and return a new line. But if you don't give a replacement string, a hash replacement, or a replacement block, you return an Enumerator object that allows you to jump to the matching fragments of the string to work later:
irb(main):022:0> s="one two three four one" => "one two three four one" irb(main):023:0> enum = s.gsub("one") => #<Enumerable::Enumerator:0x7f39a4754ab0> irb(main):024:0> enum.each_with_index {|e, i| puts "#{i}: #{e}"} 0: one 1: one => " two three four " irb(main):025:0>
source share