Class: String

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

Instance Method Summary collapse

Instance Method Details

#index_positionsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/string_expand.rb', line 11

def index_positions
  result = {}
  split('').each_with_index do |char, index|
    ascii_number = char.ord
    if (ascii_number >= 65 && ascii_number <= 90) || (ascii_number >= 97 && ascii_number <= 122)
      value = result[char]
      value = [] unless value
      value << index
      result[char] = value
    end
  end
  result
end