Created
February 6, 2011 21:57
-
-
Save daniellockard/813758 to your computer and use it in GitHub Desktop.
adds an each_word function to ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def each_word | |
self.split.each { |value| | |
return value if yield(value) | |
} | |
end | |
end |
This gist is 12 years old.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So if no code block is passed to the method, an Enumerator object will be instantiated, instead of raising a "no block given" exception such as LocalJumpError.