Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/ngrams/stdlib_ext.rb

Instance Method Summary collapse

Instance Method Details

#ngrams(n) ⇒ Object

Return the result of splitting the string into an array of ngrams of length n.



7
8
9
# File 'lib/ngrams/stdlib_ext.rb', line 7

def ngrams( n )
  (0..self.length-n).to_a.collect { |idx| self[idx,n] }
end