Skip to content

Instantly share code, notes, and snippets.

@glinesbdev
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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