Class: String

Inherits:
Object show all
Defined in:
lib/sbn/helpers.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#ngrams(len = 1) ⇒ Object

Thanks to David Alan Black for this method, from ruby-talk post #11792



48
49
50
51
52
53
54
55
56
57
# File 'lib/sbn/helpers.rb', line 48

def ngrams(len = 1)
  ngrams = []
  len = size if len > size
  (0..size - len).each do |n|
    ng = self[n...(n + len)]
    ngrams.push(ng)
    yield ng if block_given?
  end
  ngrams
end

#to_underscore_symObject



42
43
44
# File 'lib/sbn/helpers.rb', line 42

def to_underscore_sym
  self.titleize.gsub(/\s+/, '').underscore.to_sym
end