stringutilities 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/main.rb +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2781859f62a4ccb017fc1d4c3676ef72293853e
|
4
|
+
data.tar.gz: 12a31b93a69c510eedfad4771ef43a4e18283ed0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 728244ae5ca717708d462bf327854acb3dafd9131405118f56736b2219de623c2f11bc4688260bd06355000364e8ab14c7824f2d2ae1d04931cbd8fc2ffc9610
|
7
|
+
data.tar.gz: 32a2ed20caa684090b78bd829bfe4e204fe2ac8d3dcf5c2e7bae4b66f91f6a5e77de92757ec0ce02b277a82bbc8b2ae77a6909d72df5047c42d4595bdeb2faae
|
data/lib/main.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
class String
|
2
|
+
#Returns the longest word in self.
|
2
3
|
def longest_word()
|
3
4
|
longest = ""
|
4
5
|
for word in self.words()
|
@@ -8,6 +9,7 @@ class String
|
|
8
9
|
end
|
9
10
|
return longest
|
10
11
|
end
|
12
|
+
#Returns the shortest word in self.
|
11
13
|
def shortest_word()
|
12
14
|
shortest = self.words()[0]
|
13
15
|
for word in self.words()
|
@@ -39,6 +41,13 @@ class String
|
|
39
41
|
self[index1] = self[index2]
|
40
42
|
self[index2] = tempvar
|
41
43
|
end
|
44
|
+
def word_occurrences(word)
|
45
|
+
number_occurrences = 0
|
46
|
+
self.words().each() do |w|
|
47
|
+
number_occurrences += 1 if w == word
|
48
|
+
end
|
49
|
+
return number_occurrences
|
50
|
+
end
|
42
51
|
#Returns all the words in the string.
|
43
52
|
def words()
|
44
53
|
return self.split(' ')
|