Skip to content

Instantly share code, notes, and snippets.

@glinesbdev
Last active August 29, 2015 14:03
Show Gist options
  • Save glinesbdev/0cf6cbfdefb05057104c to your computer and use it in GitHub Desktop.
Save glinesbdev/0cf6cbfdefb05057104c to your computer and use it in GitHub Desktop.
File word count
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