Skip to content

Instantly share code, notes, and snippets.

@mugyu
Created February 11, 2012 21:56
Show Gist options
  • Save mugyu/1804489 to your computer and use it in GitHub Desktop.
Save mugyu/1804489 to your computer and use it in GitHub Desktop.
N-gram
class String
def ngram(n)
characters = self.each_char.to_a
return [self] if characters.size <= n
return characters.each_cons(n).map(&:join)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment