yield method automatically detects any passed code block and passes control to it : yield Method Ruby


def each_vowel
  %w{a e i o u}.each { |vowel| yield vowel }
end

each_vowel { |vowel| puts vowel }