Last active
August 29, 2015 14:03
-
-
Save glinesbdev/0cf6cbfdefb05057104c to your computer and use it in GitHub Desktop.
File word count
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
def word_count(file) | |
file = File.open(file) { |f| f.read.split } | |
file = file.reduce(:+) | |
file = file.each_char.count | |
end | |
# or you could do this | |
def word_count(file) | |
File.open(file) { |f| f.read.split } | |
.reduce(:+) | |
.each_char.count | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment