4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/sponge_mock/core_extensions/string.rb', line 4
def to_sponge_mock
return 'nice try you need to input a string'.to_sponge_mock if self.empty?
string_components = self.split(' ')
altered_components = string_components.each_with_object([]) do |word, arr|
word_length = word.length
if word_length == 1
word = word.upcase if rand(2) == 0
else
starting_index = word_length.even? ? 0 : 1
(starting_index...word_length).step(2) do |index|
word[index] = word[index].upcase
end
end
arr << word
end
altered_components.join(' ')
end
|