lite-ruby 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.fasterer.yml +19 -0
- data/.gitignore +11 -0
- data/.rspec +4 -0
- data/.rubocop.yml +32 -0
- data/.travis.yml +24 -0
- data/CHANGELOG.md +11 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +119 -0
- data/LICENSE.txt +21 -0
- data/README.md +96 -0
- data/Rakefile +8 -0
- data/_config.yml +1 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/docs/ARRAY.md +284 -0
- data/docs/DATE.md +78 -0
- data/docs/ENUMERABLE.md +174 -0
- data/docs/HASH.md +282 -0
- data/docs/INTEGER.md +43 -0
- data/docs/KERNEL.md +31 -0
- data/docs/NUMERIC.md +302 -0
- data/docs/OBJECT.md +322 -0
- data/docs/RANGE.md +55 -0
- data/docs/STRING.md +463 -0
- data/docs/TIME.md +86 -0
- data/lib/generators/lite/ruby/install_generator.rb +17 -0
- data/lib/generators/lite/ruby/templates/install.rb +15 -0
- data/lib/lite/ruby.rb +16 -0
- data/lib/lite/ruby/array.rb +290 -0
- data/lib/lite/ruby/configuration.rb +42 -0
- data/lib/lite/ruby/date.rb +27 -0
- data/lib/lite/ruby/enumerable.rb +167 -0
- data/lib/lite/ruby/hash.rb +284 -0
- data/lib/lite/ruby/helpers/date_helper.rb +105 -0
- data/lib/lite/ruby/helpers/time_helper.rb +84 -0
- data/lib/lite/ruby/integer.rb +45 -0
- data/lib/lite/ruby/kernel.rb +29 -0
- data/lib/lite/ruby/numeric.rb +210 -0
- data/lib/lite/ruby/object.rb +182 -0
- data/lib/lite/ruby/range.rb +32 -0
- data/lib/lite/ruby/string.rb +412 -0
- data/lib/lite/ruby/time.rb +26 -0
- data/lib/lite/ruby/version.rb +9 -0
- data/lite-ruby.gemspec +48 -0
- metadata +200 -0
data/docs/OBJECT.md
ADDED
@@ -0,0 +1,322 @@
|
|
1
|
+
# Object
|
2
|
+
|
3
|
+
`array?`
|
4
|
+
------
|
5
|
+
Returns if an object is an array.
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
[].array? #=> true
|
9
|
+
'test'.array? #=> false
|
10
|
+
```
|
11
|
+
|
12
|
+
`blank?`
|
13
|
+
------
|
14
|
+
Returns if an object is empty or nil.
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
''.blank? #=> true
|
18
|
+
'test'.blank? #=> false
|
19
|
+
```
|
20
|
+
|
21
|
+
`bool?`
|
22
|
+
------
|
23
|
+
Returns if an object is a `true` or `false` class.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
true.bool? #=> true
|
27
|
+
1.bool? #=> false
|
28
|
+
'false'.bool? #=> false
|
29
|
+
```
|
30
|
+
|
31
|
+
`boolean?`
|
32
|
+
------
|
33
|
+
Returns if an object is an boolean.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
true.boolean? #=> true
|
37
|
+
1.boolean? #=> true
|
38
|
+
'false'.boolean? #=> true
|
39
|
+
'foo'.boolean? #=> false
|
40
|
+
```
|
41
|
+
|
42
|
+
`date?`
|
43
|
+
------
|
44
|
+
Returns if an object is a `date`.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
Date.today.date? #=> true
|
48
|
+
'foo'.date? #=> false
|
49
|
+
```
|
50
|
+
|
51
|
+
`false?`
|
52
|
+
------
|
53
|
+
Returns if an object is `false`.
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
false.false? #=> true
|
57
|
+
true.false? #=> false
|
58
|
+
```
|
59
|
+
|
60
|
+
`falsey?`
|
61
|
+
------
|
62
|
+
Returns if an object is `false`, `nil`, or `0`.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
false.falsey? #=> true
|
66
|
+
true.falsey? #=> false
|
67
|
+
0.falsey? #=> true
|
68
|
+
```
|
69
|
+
|
70
|
+
`float?`
|
71
|
+
------
|
72
|
+
Returns if an object is a `float`.
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
1.0.float? #=> true
|
76
|
+
1.float? #=> false
|
77
|
+
```
|
78
|
+
|
79
|
+
`hash?`
|
80
|
+
------
|
81
|
+
Returns if an object is a `hash`.
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
{}.hash? #=> true
|
85
|
+
[].hash? #=> false
|
86
|
+
```
|
87
|
+
|
88
|
+
`integer?`
|
89
|
+
------
|
90
|
+
Returns if an object is a `integer`.
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
1.integer? #=> true
|
94
|
+
1.0.integer? #=> false
|
95
|
+
```
|
96
|
+
|
97
|
+
`numeric?`
|
98
|
+
------
|
99
|
+
Returns if an object is `numeric`.
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
1.numeric? #=> true
|
103
|
+
1.0.numeric? #=> true
|
104
|
+
'1.0'.numeric? #=> false
|
105
|
+
```
|
106
|
+
|
107
|
+
`numeral?`
|
108
|
+
------
|
109
|
+
Returns if an object's string value is `numeric`.
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
'-32.50'.numeral? #=> true
|
113
|
+
'$2.55'.numeral? #=> false
|
114
|
+
```
|
115
|
+
|
116
|
+
`open_struct?`
|
117
|
+
------
|
118
|
+
Returns if an object is a `open_struct`.
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
OpenStruct.new.open_struct? #=> true
|
122
|
+
1.open_struct? #=> false
|
123
|
+
```
|
124
|
+
|
125
|
+
`palindrome?`
|
126
|
+
------
|
127
|
+
Returns if an object is equal when reversed.
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
'racecar'.palindrome? #=> true
|
131
|
+
'example'.palindrome? #=> false
|
132
|
+
12321.palindrome? #=> true
|
133
|
+
12345.palindrome? #=> false
|
134
|
+
```
|
135
|
+
|
136
|
+
`present?`
|
137
|
+
------
|
138
|
+
Returns if an object is not empty or `nil`.
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
'test'.present? #=> true
|
142
|
+
''.present? #=> false
|
143
|
+
```
|
144
|
+
|
145
|
+
`range?`
|
146
|
+
------
|
147
|
+
Returns if an object is a `range`.
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
(1..2).range? #=> true
|
151
|
+
1.range? #=> false
|
152
|
+
```
|
153
|
+
|
154
|
+
`safe_call`
|
155
|
+
------
|
156
|
+
Executes the caller to an object and rescues with self.
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
callr = ->(x) { 3 * x }
|
160
|
+
|
161
|
+
3.safe_call #=> 3
|
162
|
+
callr.safe_call(3) #=> 9
|
163
|
+
callr.safe_call #=> raises ArgumentError: wrong number of arguments
|
164
|
+
```
|
165
|
+
|
166
|
+
`safe_send`
|
167
|
+
------
|
168
|
+
Executes the object method and rescues with self.
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
3.safe_send(:fake) #=> 3
|
172
|
+
3.safe_send(:to_s) #=> '3'
|
173
|
+
3.safe_send(:+, 2) #=> 5
|
174
|
+
```
|
175
|
+
|
176
|
+
`safe_try`
|
177
|
+
------
|
178
|
+
Similar to the try method but returns self instead of `nil`.
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
'example'.safe_try(:upcase) #=> 'EXAMPLE'
|
182
|
+
'example'.safe_try(:fake_method) #=> 'example'
|
183
|
+
```
|
184
|
+
|
185
|
+
`salvage`
|
186
|
+
------
|
187
|
+
Returns a placeholder if object is blank?.
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
' '.salvage #=> '---'
|
191
|
+
nil.salvage('bar') #=> 'bar'
|
192
|
+
123.salvage #=> 123
|
193
|
+
```
|
194
|
+
|
195
|
+
`send_chain`
|
196
|
+
------
|
197
|
+
Chains multiple callers to an object.
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
3.send_chain(:factorial) #=> 6
|
201
|
+
3.send_chain([:add, 4]) #=> 7
|
202
|
+
3.send_chain(:factorial, [:add, 4]) #=> 10
|
203
|
+
```
|
204
|
+
|
205
|
+
`send_chain_if`
|
206
|
+
------
|
207
|
+
Chains multiple callers to an object if it responds to the result.
|
208
|
+
|
209
|
+
```ruby
|
210
|
+
3.send_chain_if(:test) #=> 3
|
211
|
+
3.send_chain_if(:factorial) #=> 6
|
212
|
+
3.send_chain_if([:add, 4]) #=> 7
|
213
|
+
3.send_chain_if(:factorial, [:add, 4], :test) #=> 10
|
214
|
+
```
|
215
|
+
|
216
|
+
`send_if`
|
217
|
+
------
|
218
|
+
Sends a caller to an object if it responds to it.
|
219
|
+
|
220
|
+
```ruby
|
221
|
+
3.send_if(:test) #=> 3
|
222
|
+
3.send_if(:factorial) #=> 6
|
223
|
+
3.send_if(:add, 4) #=> 7
|
224
|
+
```
|
225
|
+
|
226
|
+
`set?`
|
227
|
+
------
|
228
|
+
Returns if an object is a `set`.
|
229
|
+
|
230
|
+
```ruby
|
231
|
+
Set[1, 2].set? #=> true
|
232
|
+
1.set? #=> false
|
233
|
+
```
|
234
|
+
|
235
|
+
`string?`
|
236
|
+
------
|
237
|
+
Returns if an object is a `string`.
|
238
|
+
|
239
|
+
```ruby
|
240
|
+
'foo'.string? #=> true
|
241
|
+
1.string? #=> false
|
242
|
+
```
|
243
|
+
|
244
|
+
`struct?`
|
245
|
+
------
|
246
|
+
Returns if an object is a `struct`.
|
247
|
+
|
248
|
+
```ruby
|
249
|
+
person = Struct.new(:name)
|
250
|
+
|
251
|
+
person.new('john').struct? #=> true
|
252
|
+
1.set? #=> false
|
253
|
+
```
|
254
|
+
|
255
|
+
`symbol?`
|
256
|
+
------
|
257
|
+
Returns if an object is a `symbol`.
|
258
|
+
|
259
|
+
```ruby
|
260
|
+
:foo.time? #=> true
|
261
|
+
'foo'.time? #=> false
|
262
|
+
```
|
263
|
+
|
264
|
+
`time?`
|
265
|
+
------
|
266
|
+
Returns if an object is a `time`.
|
267
|
+
|
268
|
+
```ruby
|
269
|
+
Time.now.time? #=> true
|
270
|
+
'foo'.time? #=> false
|
271
|
+
```
|
272
|
+
|
273
|
+
`true?`
|
274
|
+
------
|
275
|
+
Returns if an object is `true`.
|
276
|
+
|
277
|
+
```ruby
|
278
|
+
true.true? #=> true
|
279
|
+
false.true? #=> false
|
280
|
+
```
|
281
|
+
|
282
|
+
`truthy?`
|
283
|
+
------
|
284
|
+
Returns if an object is `true` or `1`.
|
285
|
+
|
286
|
+
```ruby
|
287
|
+
true.truthy? #=> true
|
288
|
+
false.truthy? #=> false
|
289
|
+
1.truthy? #=> true
|
290
|
+
```
|
291
|
+
|
292
|
+
`try(!)`
|
293
|
+
------
|
294
|
+
Invokes the public method whose name goes as first argument just like public_send does, except that
|
295
|
+
if the receiver does not respond to it the call returns nil rather than raising an exception.
|
296
|
+
|
297
|
+
```ruby
|
298
|
+
'example'.try(:upcase) #=> 'EXAMPLE'
|
299
|
+
'example'.try(:fake_method) #=> nil
|
300
|
+
```
|
301
|
+
|
302
|
+
`try_call`
|
303
|
+
------
|
304
|
+
Executes the caller to an object and rescues with `nil`.
|
305
|
+
|
306
|
+
```ruby
|
307
|
+
callr = ->(x) { 3 * x }
|
308
|
+
|
309
|
+
3.try_call #=> nil
|
310
|
+
callr.try_call(3) #=> 9
|
311
|
+
callr.try_call #=> raises ArgumentError: wrong number of arguments
|
312
|
+
```
|
313
|
+
|
314
|
+
`try_send`
|
315
|
+
------
|
316
|
+
Executes the object method and rescues with `nil`.
|
317
|
+
|
318
|
+
```ruby
|
319
|
+
3.try_send(:fake) #=> 3
|
320
|
+
3.try_send(:to_s) #=> '3'
|
321
|
+
3.try_send(:+, 2) #=> 5
|
322
|
+
```
|
data/docs/RANGE.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Range
|
2
|
+
|
3
|
+
`combine`
|
4
|
+
------
|
5
|
+
Returns two concatenated ranges.
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
(1..3).combine(7..9) #=> [1, 2, 3, 7, 8, 9]
|
9
|
+
```
|
10
|
+
|
11
|
+
`include_with_range?`
|
12
|
+
------
|
13
|
+
Returns if a range is within another open ended range.
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
(1..5).include_with_range?(1) # => true
|
17
|
+
(1..5).include_with_range?(2..3) # => true
|
18
|
+
(1..5).include_with_range?(7) # => false
|
19
|
+
(1..5).include_with_range?(2..6) # => false
|
20
|
+
```
|
21
|
+
|
22
|
+
`overlaps?`
|
23
|
+
------
|
24
|
+
Returns if two ranges overlap each other.
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
(1..5).overlaps?(4..6) # => true
|
28
|
+
(1..5).overlaps?(7..9) # => false
|
29
|
+
```
|
30
|
+
|
31
|
+
`sample`
|
32
|
+
------
|
33
|
+
Returns a random element from the range.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
(1..5).sample # => 4
|
37
|
+
```
|
38
|
+
|
39
|
+
`shuffle(!)`
|
40
|
+
------
|
41
|
+
Returns a copy of a shuffled range of elements.
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
(1..5).shuffle # => [2, 5, 1, 4, 3]
|
45
|
+
(1..5).shuffle! # => [3, 4, 5, 2, 1]
|
46
|
+
```
|
47
|
+
|
48
|
+
`within?`
|
49
|
+
------
|
50
|
+
Returns if one range is within another.
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
(1..5).within?(2..4) # => true
|
54
|
+
(1..5).within?(4..6) # => false
|
55
|
+
```
|
data/docs/STRING.md
ADDED
@@ -0,0 +1,463 @@
|
|
1
|
+
# String
|
2
|
+
|
3
|
+
`any?`
|
4
|
+
------
|
5
|
+
Returns if a string includes a set of string(s).
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
'example string'.any?('foo') #=> false
|
9
|
+
'example string'.any?('foo', 'string') #=> true
|
10
|
+
```
|
11
|
+
|
12
|
+
`at`
|
13
|
+
------
|
14
|
+
Returns the characters at index position, matching string, or regex.
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
'example_string'.at(0) #=> 'e'
|
18
|
+
'example_string'.at(-2) #=> 'n'
|
19
|
+
'example_string'.at(1..3) #=> 'xam'
|
20
|
+
'example_string'.at('e_s') #=> 'e_s'
|
21
|
+
'example_string'.at(/ple/) #=> 'ple'
|
22
|
+
'example_string'.at(99) #=> nil
|
23
|
+
```
|
24
|
+
|
25
|
+
`camelize(!)` aka `camelcase(!)`
|
26
|
+
------
|
27
|
+
Transforms a string to camelcase.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
'example_string'.camelize #=> 'ExampleString'
|
31
|
+
'example_String'.camecase #=> 'ExampleString'
|
32
|
+
'example_string'.camelize(:lower) #=> 'exampleString'
|
33
|
+
'example_String'.camecase(:lower) #=> 'exampleString'
|
34
|
+
```
|
35
|
+
|
36
|
+
`classify(!)`
|
37
|
+
------
|
38
|
+
Transforms a string to a class name like Rails does for table names to models.
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
'example_string'.classify #=> 'ExampleString'
|
42
|
+
'example_string/test'.classify #=> 'ExampleString::Test'
|
43
|
+
'example_string.test'.classify #=> 'Test'
|
44
|
+
```
|
45
|
+
|
46
|
+
`constantize`
|
47
|
+
------
|
48
|
+
Converts a string in an object.
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
'Example::String'.constantize #=> Class Object
|
52
|
+
```
|
53
|
+
|
54
|
+
`dasherize(!)`
|
55
|
+
------
|
56
|
+
Replaces underscores with dashes in the string.
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
'example_string'.dasherize #=> 'example-string'
|
60
|
+
```
|
61
|
+
|
62
|
+
`deconstantize(!)`
|
63
|
+
------
|
64
|
+
Removes the rightmost segment from the constant expression in the string.
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
'Example::String'.deconstantize # => 'Example'
|
68
|
+
'::Example::String'.deconstantize # => '::Example'
|
69
|
+
'String'.deconstantize # => ''
|
70
|
+
'::String'.deconstantize # => ''
|
71
|
+
''.deconstantize # => ''
|
72
|
+
```
|
73
|
+
|
74
|
+
`demodulize(!)`
|
75
|
+
------
|
76
|
+
Removes the module part from the expression in the string.
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
'Example::String'.demodulize #=> 'String'
|
80
|
+
'String'.demodulize #=> 'String'
|
81
|
+
```
|
82
|
+
|
83
|
+
`domain`
|
84
|
+
------
|
85
|
+
Extracts the domain name from a URL.
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
'http://www.example.com/fake-page'.domain #=> 'www.example.com'
|
89
|
+
'example string'.domain #=> 'example string'
|
90
|
+
```
|
91
|
+
|
92
|
+
`downcase?`
|
93
|
+
------
|
94
|
+
Returns true if all characters are lowercase.
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
'example'.downcase? #=> true
|
98
|
+
'Example'.downcase? #=> false
|
99
|
+
'EXAMPLE'.downcase? #=> false
|
100
|
+
```
|
101
|
+
|
102
|
+
`ellipsize`
|
103
|
+
------
|
104
|
+
Truncate a string in the middle.
|
105
|
+
|
106
|
+
Option | Type | Default
|
107
|
+
--- | --- | ---
|
108
|
+
offset | integer | 4
|
109
|
+
separator | string | ' '
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.ellipsize(30) #=> '0123...WXYZ'
|
113
|
+
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.ellipsize(50) #=> '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
114
|
+
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.ellipsize(30, offset: 2) #=> '01...YZ'
|
115
|
+
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.ellipsize(30, separator: '+++') #=> '0123+++WXYZ'
|
116
|
+
```
|
117
|
+
|
118
|
+
`first`
|
119
|
+
------
|
120
|
+
Returns the first character. If a limit is supplied, Returns a substring from the beginning of the
|
121
|
+
string until it reaches the limit value. If the given limit is greater than or equal to the string
|
122
|
+
length, Returns a copy of self.
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
'example'.first #=> 'e'
|
126
|
+
'example'.first(0) #=> ''
|
127
|
+
'example'.first(3) #=> 'exa'
|
128
|
+
```
|
129
|
+
|
130
|
+
`format`
|
131
|
+
------
|
132
|
+
Returns an interpolated string that allows for options.
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
'example %s'.format('string') #=> 'example string'
|
136
|
+
'test %{one} %{two}'.format(one: 'example', two: 'string') #=> 'test example string'
|
137
|
+
'%d + %d'.format([1, 2]) #=> '1 + 2'
|
138
|
+
```
|
139
|
+
|
140
|
+
`from`
|
141
|
+
------
|
142
|
+
Returns a substring from the given position to the end of the string. If the position is negative, it is counted from the end of the string.
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
'example'.from(0) #=> 'example'
|
146
|
+
'example'.from(3) #=> 'mple'
|
147
|
+
```
|
148
|
+
|
149
|
+
`headerize(!)`
|
150
|
+
------
|
151
|
+
Capitalizes each word.
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
' example test-sample '.headerize #=> 'Example Test-sample'
|
155
|
+
```
|
156
|
+
|
157
|
+
`humanize(!)`
|
158
|
+
------
|
159
|
+
Transforms a string to a human readable string.
|
160
|
+
|
161
|
+
Option | Type | Default
|
162
|
+
--- | --- | ---
|
163
|
+
capitalize | boolean | true
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
'ExampleString'.humanize #=> 'Example string'
|
167
|
+
'_example_string_id'.humanize #=> 'Example string'
|
168
|
+
'example_string'.humanize(capitalize: false) #=> 'example string'
|
169
|
+
```
|
170
|
+
|
171
|
+
`indent(!)`
|
172
|
+
------
|
173
|
+
Indents the lines in the receiver.
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
'example'.indent(2) #=> ' example'
|
177
|
+
'example'.indent(2, '\t') #=> '\t\texample'
|
178
|
+
```
|
179
|
+
|
180
|
+
`index_all`
|
181
|
+
------
|
182
|
+
Returns the index values of matching patterns.
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
'012324507654301243'.index_all(0) #=> [0,7,13]
|
186
|
+
'the apple is the best fruit in the world'.index_all('the') #=> [0,13,31]
|
187
|
+
'asdfasdfasdf'.index_all(/sd/) #=> [1,5,9]
|
188
|
+
```
|
189
|
+
|
190
|
+
`labelize(!)`
|
191
|
+
------
|
192
|
+
Transforms a string to a human readable string.
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
'example string'.labelize #=> 'Example string'
|
196
|
+
'_example_string_id'.labelize #=> 'Example string ID'
|
197
|
+
'ExampleString'.labelize #=> 'Example string'
|
198
|
+
```
|
199
|
+
|
200
|
+
`last`
|
201
|
+
------
|
202
|
+
Returns the last character of the string. If a limit is supplied, Returns a substring from the end
|
203
|
+
of the string until it reaches the limit value (counting backwards). If the given limit is greater
|
204
|
+
than or equal to the string length, Returns a copy of self.
|
205
|
+
|
206
|
+
```ruby
|
207
|
+
'example'.last #=> 'e'
|
208
|
+
'example'.last(0) #=> ''
|
209
|
+
'example'.first(3) #=> 'ple'
|
210
|
+
```
|
211
|
+
|
212
|
+
`mixcase?`
|
213
|
+
------
|
214
|
+
Returns true if characters are mixedcase.
|
215
|
+
|
216
|
+
```ruby
|
217
|
+
'Example'.mixedcase? #=> true
|
218
|
+
'EXAMPLE'.mixedcase? #=> false
|
219
|
+
'example'.mixedcase? #=> false
|
220
|
+
```
|
221
|
+
|
222
|
+
`ordinal`
|
223
|
+
------
|
224
|
+
Returns the suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
|
225
|
+
|
226
|
+
```ruby
|
227
|
+
'1'.ordinal #=> 'th'
|
228
|
+
'2'.ordinal #=> 'nd'
|
229
|
+
'3'.ordinal #=> 'rd'
|
230
|
+
'11'.ordinal #=> 'th'
|
231
|
+
```
|
232
|
+
|
233
|
+
`ordinalize`
|
234
|
+
------
|
235
|
+
Transforms a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
|
236
|
+
|
237
|
+
```ruby
|
238
|
+
'1'.ordinalize #=> '1th'
|
239
|
+
'2'.ordinalize #=> '2nd'
|
240
|
+
'3'.ordinalize #=> '3rd'
|
241
|
+
'11'.ordinalize #=> '4th'
|
242
|
+
```
|
243
|
+
|
244
|
+
`parameterize(!)`
|
245
|
+
------
|
246
|
+
Makes a string suitable for a dashed url parameter string.
|
247
|
+
|
248
|
+
```ruby
|
249
|
+
'example_string'.parameterize #=> 'example-string'
|
250
|
+
'example_string'.parameterize(separator: '?') #=> 'example?string'
|
251
|
+
```
|
252
|
+
|
253
|
+
`pollute(!)`
|
254
|
+
------
|
255
|
+
Pollutes the space between every letter in a string, so it will be exempt from any impending string searches.
|
256
|
+
|
257
|
+
```ruby
|
258
|
+
'test'.pollute #=> 't^--^--^e^--^--^s^--^--^t^--^--^'
|
259
|
+
'test'.pollute('-') #=> 't-e-s-t-'
|
260
|
+
```
|
261
|
+
|
262
|
+
`pop`
|
263
|
+
------
|
264
|
+
Returns the last character of a string.
|
265
|
+
|
266
|
+
```ruby
|
267
|
+
'test'.pop #=> 't'
|
268
|
+
```
|
269
|
+
|
270
|
+
`push`
|
271
|
+
------
|
272
|
+
Concats string to self.
|
273
|
+
|
274
|
+
```ruby
|
275
|
+
'test'.push('er') #=> 'tester'
|
276
|
+
```
|
277
|
+
|
278
|
+
`remove(!)`
|
279
|
+
------
|
280
|
+
Removes every instance of a string.
|
281
|
+
|
282
|
+
```ruby
|
283
|
+
'this thing that thing'.remove('thing') #=> 'this that '
|
284
|
+
'this thing that thing'.remove(1..3) #=> 't thing that thing'
|
285
|
+
'this thing that them'.remove('thing', 'them') #=> 'this that '
|
286
|
+
'this thing that them'.remove('thing', 1..3) #=> 't that them'
|
287
|
+
```
|
288
|
+
|
289
|
+
`remove_tags(!)`
|
290
|
+
------
|
291
|
+
Removes HTML tags from a string.
|
292
|
+
|
293
|
+
```ruby
|
294
|
+
'example'.remove_tags #=> 'example'
|
295
|
+
'<a href='http://example.com'>click</a>'.remove_tags #=> 'click'
|
296
|
+
'this is <b>bold</b> and <em>emphatic</em>'.remove_tags #=> 'this is bold and emphatic'
|
297
|
+
```
|
298
|
+
|
299
|
+
`sample(!)`
|
300
|
+
------
|
301
|
+
Removes a random value and returns that value.
|
302
|
+
|
303
|
+
```ruby
|
304
|
+
'this thing that'.sample #=> 'thing'
|
305
|
+
'this thing that'.sample(' thing ') #=> 'that'
|
306
|
+
```
|
307
|
+
|
308
|
+
`shift(!)`
|
309
|
+
------
|
310
|
+
Removes the first instance of a string.
|
311
|
+
|
312
|
+
```ruby
|
313
|
+
'this thing that thing'.shift #=> 't'
|
314
|
+
'this thing that thing'.shift('thing') #=> 'this that thing'
|
315
|
+
'this thing that thing'.shift('this', 'that') #=> ' thing thing'
|
316
|
+
```
|
317
|
+
|
318
|
+
`shuffle(!)`
|
319
|
+
------
|
320
|
+
Randomizes the characters in a string.
|
321
|
+
|
322
|
+
```ruby
|
323
|
+
'ruby rules'.sample #=> 'e lybrsuur'
|
324
|
+
'ruby rules'.sample! #=> 'rblse syru'
|
325
|
+
```
|
326
|
+
|
327
|
+
`sift(!)`
|
328
|
+
------
|
329
|
+
Returns a string matching any character in a pattern.
|
330
|
+
|
331
|
+
```ruby
|
332
|
+
'qa2ws3ed4rf5tg6yh7uj8ik9ol'.sift('0123456789') #=> '23456789'
|
333
|
+
'qa2ws3ed4rf5tg6yh7uj8ik9ol'.sift(0..9) #=> '23456789'
|
334
|
+
'qa2ws3ed4rf5tg6yh7uj8ik9ol'.sift([0,1,2,3,4,5,6,7,8,9]) #=> '23456789'
|
335
|
+
```
|
336
|
+
|
337
|
+
`slugify(!)`
|
338
|
+
------
|
339
|
+
Returns a permalink-style string, with odd characters removed.
|
340
|
+
|
341
|
+
```ruby
|
342
|
+
'example'.slugify #=> 'example'
|
343
|
+
'example string'.slugify #=> 'example-string'
|
344
|
+
'Example string @@@ test!'.slugify #=> 'example-string-test'
|
345
|
+
```
|
346
|
+
|
347
|
+
`sort(!)`
|
348
|
+
------
|
349
|
+
Returns a sorted a string.
|
350
|
+
|
351
|
+
```ruby
|
352
|
+
'adbec'.sort #=> 'abcde'
|
353
|
+
```
|
354
|
+
|
355
|
+
`squish(!)`
|
356
|
+
------
|
357
|
+
Returns the string, first removing all whitespace on both ends of the string, and then changing
|
358
|
+
remaining consecutive whitespace groups into one space each.
|
359
|
+
|
360
|
+
```ruby
|
361
|
+
'example string'.squish #=> 'example string'
|
362
|
+
'example \n \t string'.squish #=> 'example string'
|
363
|
+
' example string '.squish #=> 'example string'
|
364
|
+
```
|
365
|
+
|
366
|
+
`titleize(!)`
|
367
|
+
------
|
368
|
+
Capitalizes each word in a string.
|
369
|
+
|
370
|
+
```ruby
|
371
|
+
'example string'.titleize #=> 'Example String'
|
372
|
+
'_example_string_id'.titleize #=> 'Example String'
|
373
|
+
'ExampleString'.titleize #=> 'Example String'
|
374
|
+
```
|
375
|
+
|
376
|
+
`to`
|
377
|
+
------
|
378
|
+
Returns a substring from the beginning of the string to the given position.
|
379
|
+
If the position is negative, it is counted from the end of the string.
|
380
|
+
|
381
|
+
```ruby
|
382
|
+
'example'.to(0) #=> 'example'
|
383
|
+
'example'.to(3) #=> 'exam'
|
384
|
+
'example'.to(-2) #=> 'exampl'
|
385
|
+
```
|
386
|
+
|
387
|
+
`transliterize(!)`
|
388
|
+
------
|
389
|
+
Returns a string with swapped special characters.
|
390
|
+
|
391
|
+
```ruby
|
392
|
+
'źåöé'.transliterize #=> 'zaoe'
|
393
|
+
```
|
394
|
+
|
395
|
+
`truncate`
|
396
|
+
------
|
397
|
+
Retuns a trimmed string after a given length if string is longer than length.
|
398
|
+
|
399
|
+
Option | Type | Default
|
400
|
+
--- | --- | ---
|
401
|
+
omission | string | '...'
|
402
|
+
separator | string | ' '
|
403
|
+
|
404
|
+
```ruby
|
405
|
+
'example string'.truncate(3) #=> '...'
|
406
|
+
'example string'.truncate(6) #=> 'exa...'
|
407
|
+
'example string'.truncate(12, separator: ' ') #=> 'example...'
|
408
|
+
'example string'.truncate(13, omission: '... (more)') #=> 'exa... (more)'
|
409
|
+
'example string'.truncate(15) #=> 'example string'
|
410
|
+
```
|
411
|
+
|
412
|
+
`truncate_words`
|
413
|
+
------
|
414
|
+
Truncates a given text after a given number of words.
|
415
|
+
|
416
|
+
Option | Type | Default
|
417
|
+
--- | --- | ---
|
418
|
+
omission | string | '...'
|
419
|
+
separator | string | ' '
|
420
|
+
|
421
|
+
```ruby
|
422
|
+
'example string test'.truncate_words(1) #=> 'example...'
|
423
|
+
'Once<br>upon<br>a<br>time<br>in<br>a<br>world'.truncate_words(5, separator: '<br>') #=> 'Once<br>upon<br>a<br>time<br>in...'
|
424
|
+
'And they found that many people were sleeping better.'.truncate_words(5, omission: '... (continued)') #=> 'And they found that many... (continued)'
|
425
|
+
```
|
426
|
+
|
427
|
+
`underscore(!)`
|
428
|
+
------
|
429
|
+
Transforms a string to snake case.
|
430
|
+
|
431
|
+
```ruby
|
432
|
+
'ExampleString'.underscore #=> 'example_string'
|
433
|
+
'exampleString'.underscore #=> 'example_string'
|
434
|
+
'ExampleString::Test'.underscore #=> 'example_string/test'
|
435
|
+
```
|
436
|
+
|
437
|
+
`unpollute(!)`
|
438
|
+
------
|
439
|
+
Removes the default or custom pollution character. Can also be used to remove an unwanted character.
|
440
|
+
|
441
|
+
```ruby
|
442
|
+
't^--^--^e^--^--^s^--^--^t^--^--^'.unpollute #=> 'test'
|
443
|
+
't-e-s-t-'.unpollute #=> 'test'
|
444
|
+
```
|
445
|
+
|
446
|
+
`upcase?`
|
447
|
+
------
|
448
|
+
Returns true if all characters are uppercase.
|
449
|
+
|
450
|
+
```ruby
|
451
|
+
'EXAMPLE'.upcase? #=> true
|
452
|
+
'example'.upcase? #=> false
|
453
|
+
'Example'.upcase? #=> false
|
454
|
+
```
|
455
|
+
|
456
|
+
`unshift(!)`
|
457
|
+
------
|
458
|
+
Prepends string(s) to self.
|
459
|
+
|
460
|
+
```ruby
|
461
|
+
'this thing that thing'.unshift('thing ') #=> 'thing this thing that thing'
|
462
|
+
'this thing that thing'.unshift('this ', 'that ') #=> 'this that this thing that thing'
|
463
|
+
```
|