Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/word_up.rb
Instance Method Summary collapse
Instance Method Details
#capitalized? ⇒ Boolean
21 22 23 |
# File 'lib/word_up.rb', line 21 def capitalized? self.capitalize == self end |
#word_after(w) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/word_up.rb', line 12 def word_after(w) sentence = self.gsub(/[^0-9a-z ]/i, '').split downcased = sentence.map(&:downcase) param_index = downcased.index(w.downcase) unless param_index.nil? sentence[param_index + 1] end end |
#word_distance(w1, w2) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/word_up.rb', line 5 def word_distance(w1, w2) sentence = self.gsub(/[^0-9a-z ]/i, '').split w1_index = sentence.index(w1.gsub(/[^0-9a-z ]/i, '')) w2_index = sentence.index(w2.gsub(/[^0-9a-z ]/i, '')) ((w1_index - w2_index).abs - 1) end |