stringutilities 0.0.2
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 +7 -0
- data/lib/main.rb +46 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 45e438f4f5bb37922529d0ec5d7a11961c332100
|
4
|
+
data.tar.gz: 68cd2398c9c1041ab163e3c96453c1a4c5174252
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 91fd1227178ad7f1740eab7a8b280f0d015cae807b7f2ceb3221bcccca9af07aea436c129e4dfd2039575b72833c1be8ff82dfd1f70ec534a7f9edc67ed73315
|
7
|
+
data.tar.gz: 9bd2b457d64050a2f1ad521b425e1c2c505c60b67128b7ac77a169254ed07a6f906d96bf0b3b231418b6924bcca5f5a5556794059da40d353a7f51aa137ad783
|
data/lib/main.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
class String
|
2
|
+
def longest_word()
|
3
|
+
longest = ""
|
4
|
+
for word in self.words()
|
5
|
+
if word.length() > longest.length()
|
6
|
+
longest = word
|
7
|
+
end
|
8
|
+
end
|
9
|
+
return longest
|
10
|
+
end
|
11
|
+
def shortest_word()
|
12
|
+
shortest = self.words()[0]
|
13
|
+
for word in self.words()
|
14
|
+
if word.length() < shortest.length()
|
15
|
+
shortest = word
|
16
|
+
end
|
17
|
+
end
|
18
|
+
return shortest
|
19
|
+
end
|
20
|
+
#Returns the number of times match_character occurs.
|
21
|
+
def occurrences(match_character)
|
22
|
+
number_occurrences = 0
|
23
|
+
self.chars().each() do |c|
|
24
|
+
number_occurrences += 1 if c == match_character
|
25
|
+
end
|
26
|
+
return number_occurrences
|
27
|
+
end
|
28
|
+
#Swaps the values at index1 and index2 and returns the results in a new string.
|
29
|
+
def swap(index1, index2)
|
30
|
+
return_string = self
|
31
|
+
tempvar = return_string[index1]
|
32
|
+
return_string[index1] = return_string[index2]
|
33
|
+
return_string[index2] = tempvar
|
34
|
+
return return_string
|
35
|
+
end
|
36
|
+
#Swaps the values at index1 and index2.
|
37
|
+
def swap!(index1, index2)
|
38
|
+
tempvar = self[index1]
|
39
|
+
self[index1] = self[index2]
|
40
|
+
self[index2] = tempvar
|
41
|
+
end
|
42
|
+
#Returns all the words in the string.
|
43
|
+
def words()
|
44
|
+
return self.split(' ')
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stringutilities
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- SugarRush
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |-
|
14
|
+
This gem adds several methods to the String class. It will be updated frequently to
|
15
|
+
add new methods. All methods have been thoroughly tested and definitely work.
|
16
|
+
email:
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/main.rb
|
22
|
+
homepage: http://rubygems.org/gems/stringutilities
|
23
|
+
licenses: []
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.6.14.1
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: A gem that adds some string utility methods
|
45
|
+
test_files: []
|