active_object 4.0.5 → 4.0.6
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/README.md +221 -212
- data/active_object.gemspec +1 -0
- data/lib/active_object.rb +1 -1
- data/lib/active_object/numeric.rb +15 -18
- data/lib/active_object/object.rb +4 -0
- data/lib/active_object/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6dad4873c7489d7788c743091ec81a84c11c33d
|
4
|
+
data.tar.gz: fd45601baaa954092855455c9be8daf69265481f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8b1e6fe19500de6943514188a0151b8c51482417745245aab7428a0fb472529be513c52aafc54cb460a210ef312a6935882b2a29fb43e3dd9d47e455799cc4e
|
7
|
+
data.tar.gz: d5dae3733f81cf7abaefd32b58856e77724fc1eec4b212512015854d8a7970b22e864da86adbc775165e3f27f69e32bddca4cc6a37b20b88d9d754ced043da7a
|
data/README.md
CHANGED
@@ -46,7 +46,7 @@ Or install it yourself as:
|
|
46
46
|
`../config/initalizers/active_object.rb`
|
47
47
|
|
48
48
|
```ruby
|
49
|
-
ActiveObject.configure do |config|
|
49
|
+
ActiveObject::Settings.configure do |config|
|
50
50
|
config.autoload_array = true
|
51
51
|
config.autoload_date = true
|
52
52
|
config.autoload_enumerable = true
|
@@ -62,7 +62,7 @@ end
|
|
62
62
|
|
63
63
|
## Array
|
64
64
|
|
65
|
-
|
65
|
+
**After:**
|
66
66
|
`after` returns the value after the given value.
|
67
67
|
|
68
68
|
```ruby
|
@@ -71,7 +71,7 @@ end
|
|
71
71
|
['1', '2', '3'].after('4') #=> nil
|
72
72
|
```
|
73
73
|
|
74
|
-
|
74
|
+
**Before:**
|
75
75
|
`before` returns the value before the given value.
|
76
76
|
|
77
77
|
```ruby
|
@@ -80,35 +80,35 @@ end
|
|
80
80
|
['1', '2', '3'].before('4') #=> nil
|
81
81
|
```
|
82
82
|
|
83
|
-
|
83
|
+
**Delete First:**
|
84
84
|
`delete_first` and `delete_first!` removes the first element from an array. Like Array.shift, but returns the array instead of the removed element.
|
85
85
|
|
86
86
|
```ruby
|
87
87
|
['1', '2', '3'].delete_first #=> ['2', '3']
|
88
88
|
```
|
89
89
|
|
90
|
-
|
90
|
+
**Delete Last:**
|
91
91
|
`delete_last` and `delete_last!` removes the last element from an array. Like Array.pop, but returns the array instead of the removed element.
|
92
92
|
|
93
93
|
```ruby
|
94
94
|
['1', '2', '3'].delete_last #=> ['1', '2']
|
95
95
|
```
|
96
96
|
|
97
|
-
|
97
|
+
**Delete Values:**
|
98
98
|
`delete_values` delete multiple values from array.
|
99
99
|
|
100
100
|
```ruby
|
101
101
|
[1, 2, 3, 4].delete_values(1, 3) #=> [2, 4]
|
102
102
|
```
|
103
103
|
|
104
|
-
|
104
|
+
**Dig:**
|
105
105
|
`dig` returns the value of a nested array.
|
106
106
|
|
107
107
|
```ruby
|
108
108
|
['zero', ['ten', 'eleven', 'twelve'], 'two'].dig(1, 2) #=> 'twelve'
|
109
109
|
```
|
110
110
|
|
111
|
-
|
111
|
+
**Duplicates:**
|
112
112
|
`duplicates` returns list of duplicate elements.
|
113
113
|
|
114
114
|
```ruby
|
@@ -116,7 +116,7 @@ end
|
|
116
116
|
[1, 1, 2, 2, 2, 3].duplicates(3) #=> [2]
|
117
117
|
```
|
118
118
|
|
119
|
-
|
119
|
+
**From:**
|
120
120
|
`from` returns the tail of the array from position.
|
121
121
|
|
122
122
|
```ruby
|
@@ -125,14 +125,14 @@ end
|
|
125
125
|
['1', '2', '3'].from(-1) #=> ['3']
|
126
126
|
```
|
127
127
|
|
128
|
-
|
128
|
+
**Groups:**
|
129
129
|
`groups` splits or iterates over the array in number of groups.
|
130
130
|
|
131
131
|
```ruby
|
132
132
|
%w(1 2 3 4 5 6 7 8 9 10).groups(3) #=> [['1', '2', '3', '4'], ['5', '6', '7'], ['8', '9', '10']]
|
133
133
|
```
|
134
134
|
|
135
|
-
|
135
|
+
**In Groups:**
|
136
136
|
`in_groups` splits or iterates over the array in number of groups, padding any remaining slots with fill_with unless it is false.
|
137
137
|
|
138
138
|
```ruby
|
@@ -141,7 +141,7 @@ end
|
|
141
141
|
%w(1 2 3 4 5 6 7 8 9 10).in_groups(3, false) #=> [['1', '2', '3', '4'], ['5', '6', '7'], ['8', '9', '10']]
|
142
142
|
```
|
143
143
|
|
144
|
-
|
144
|
+
**In Groups Of:**
|
145
145
|
`in_groups_of` splits or iterates over the array in groups of size number, padding any remaining slots with fill_with unless it is false.
|
146
146
|
|
147
147
|
```ruby
|
@@ -150,7 +150,7 @@ end
|
|
150
150
|
%w(1 2 3 4 5 6 7 8 9 10).in_groups_of(3, false) #=> [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9'], ['10']]
|
151
151
|
```
|
152
152
|
|
153
|
-
|
153
|
+
**Percentile:**
|
154
154
|
`percentile` returns the percentile value for a given percentage.
|
155
155
|
|
156
156
|
```ruby
|
@@ -159,28 +159,28 @@ end
|
|
159
159
|
[1, 2, 3, 4, 5].percentile(50) # => 3
|
160
160
|
```
|
161
161
|
|
162
|
-
|
162
|
+
**Probablity:**
|
163
163
|
`probability` generates a hash mapping each unique element in the array to the relative frequency, i.e. the probablity, of it appearence.
|
164
164
|
|
165
165
|
```ruby
|
166
166
|
[:a, :b, :c, :c].probability #=> { a: 0.25, b: 0.25, c: 0.5 }
|
167
167
|
```
|
168
168
|
|
169
|
-
|
169
|
+
**Reject Values:**
|
170
170
|
`reject_values` delete multiple values from array from a array copy.
|
171
171
|
|
172
172
|
```ruby
|
173
173
|
[1, 2, 3, 4, 5].reject_values(2,4) #=> [1, 3, 5]
|
174
174
|
```
|
175
175
|
|
176
|
-
|
176
|
+
**Sample:**
|
177
177
|
`sample!` deletes a random value and returns that value.
|
178
178
|
|
179
179
|
```ruby
|
180
180
|
[1, 2, 3, 4, 5].sample! #=> 2
|
181
181
|
```
|
182
182
|
|
183
|
-
|
183
|
+
**Split:**
|
184
184
|
`split` divides the array into one or more subarrays based on a delimiting value or the result of an optional block.
|
185
185
|
|
186
186
|
```ruby
|
@@ -188,7 +188,7 @@ end
|
|
188
188
|
(1..10).to_a.split { |i| i % 3 == 0 } # => [[1, 2], [4, 5], [7, 8], [10]]
|
189
189
|
```
|
190
190
|
|
191
|
-
|
191
|
+
**Strip:**
|
192
192
|
`strip` and `strip!` removes blank elements from an array.
|
193
193
|
|
194
194
|
```ruby
|
@@ -196,7 +196,7 @@ end
|
|
196
196
|
'this is a test'.split(' ').strip #=> ['this', 'is', 'a', 'test']
|
197
197
|
```
|
198
198
|
|
199
|
-
|
199
|
+
**To:**
|
200
200
|
`to` returns the beginning of the array up to position.
|
201
201
|
|
202
202
|
```ruby
|
@@ -205,7 +205,7 @@ end
|
|
205
205
|
['1', '2', '3'].to(-1) #=> ['3']
|
206
206
|
```
|
207
207
|
|
208
|
-
|
208
|
+
**To Sentence:**
|
209
209
|
`to_sentence` converts the array to a comma-separated sentence where the last element is joined by the connector word.
|
210
210
|
|
211
211
|
**Options:**
|
@@ -224,14 +224,14 @@ end
|
|
224
224
|
|
225
225
|
## Enumerable
|
226
226
|
|
227
|
-
|
227
|
+
**Cluster:**
|
228
228
|
`cluster` clusters together adjacent elements into a list of sub-arrays.
|
229
229
|
|
230
230
|
```ruby
|
231
231
|
[2,2,2,3,3,4,2,2,1].cluster { |x| x } #=> [[2, 2, 2], [3, 3], [4], [2, 2], [1]]
|
232
232
|
```
|
233
233
|
|
234
|
-
|
234
|
+
**Difference:**
|
235
235
|
`difference` returns the difference of a collection of numbers.
|
236
236
|
|
237
237
|
```ruby
|
@@ -240,7 +240,7 @@ end
|
|
240
240
|
[1,2,3].difference #=> -4
|
241
241
|
```
|
242
242
|
|
243
|
-
|
243
|
+
**Divisible:**
|
244
244
|
`divisible` returns the division of a collection of numbers.
|
245
245
|
|
246
246
|
```ruby
|
@@ -249,7 +249,7 @@ end
|
|
249
249
|
[16,4,2].divisible #=> 2
|
250
250
|
```
|
251
251
|
|
252
|
-
|
252
|
+
**Drop Last:**
|
253
253
|
`drop_last` drops the last number of elements of a collection.
|
254
254
|
|
255
255
|
```ruby
|
@@ -258,7 +258,7 @@ end
|
|
258
258
|
[1,2,3].drop_last(2) #=> [1]
|
259
259
|
```
|
260
260
|
|
261
|
-
|
261
|
+
**Drop Last If:**
|
262
262
|
`drop_last_if` drops the last number of elements of a collection while it meets a criteria.
|
263
263
|
|
264
264
|
```ruby
|
@@ -267,7 +267,7 @@ end
|
|
267
267
|
[1,2,3,4].drop_last_if(&:odd?) #=> [1,2,3,4]
|
268
268
|
```
|
269
269
|
|
270
|
-
|
270
|
+
**Exactly:**
|
271
271
|
`exactly?` returns if there are exactly the number of an element type.
|
272
272
|
|
273
273
|
```ruby
|
@@ -276,7 +276,7 @@ end
|
|
276
276
|
[1,1,3,3].exactly?(2, &:even?) #=> false
|
277
277
|
```
|
278
278
|
|
279
|
-
|
279
|
+
**Exclude:**
|
280
280
|
`exclude?` returns true if the collection does not include the object.
|
281
281
|
|
282
282
|
```ruby
|
@@ -284,14 +284,14 @@ end
|
|
284
284
|
[1, 2, 3].exclude?(3) #=> false
|
285
285
|
```
|
286
286
|
|
287
|
-
|
287
|
+
**Expand:**
|
288
288
|
`expand` expand all elements of an Enumerable object.
|
289
289
|
|
290
290
|
```ruby
|
291
291
|
[0, 2..3, 5..7].expand #=> [0,[2, 3],[5,6,7]]
|
292
292
|
```
|
293
293
|
|
294
|
-
|
294
|
+
**Exponential:**
|
295
295
|
`exponential` returns the exponential of a collection of numbers.
|
296
296
|
|
297
297
|
```ruby
|
@@ -300,7 +300,7 @@ end
|
|
300
300
|
[2,3,4].exponential #=> 4096
|
301
301
|
```
|
302
302
|
|
303
|
-
|
303
|
+
**Frequencies:**
|
304
304
|
`frequencies` returns a hash of the number of times a value in an array appears.
|
305
305
|
|
306
306
|
```ruby
|
@@ -308,7 +308,7 @@ end
|
|
308
308
|
[1, :symbol, 'string', 3, :symbol, 1].frequencies #=> { 1 => 2, :symbol => 2, 'string' => 1, 3 => 1 }
|
309
309
|
```
|
310
310
|
|
311
|
-
|
311
|
+
**Incase:**
|
312
312
|
`incase?` the same as #include? but tested using #=== instead of #==.
|
313
313
|
|
314
314
|
```ruby
|
@@ -316,7 +316,7 @@ end
|
|
316
316
|
[1, 2, 'a'].incase?(3) #=> false
|
317
317
|
```
|
318
318
|
|
319
|
-
|
319
|
+
**Many:**
|
320
320
|
`many?` returns if collection has more than one element while respecting nil and false as an element.
|
321
321
|
|
322
322
|
```ruby
|
@@ -327,7 +327,7 @@ end
|
|
327
327
|
|
328
328
|
```
|
329
329
|
|
330
|
-
|
330
|
+
**Max:**
|
331
331
|
`max` returns the largest value of a collection of numbers.
|
332
332
|
|
333
333
|
```ruby
|
@@ -336,7 +336,7 @@ end
|
|
336
336
|
[1,2,3].max #=> 3
|
337
337
|
```
|
338
338
|
|
339
|
-
|
339
|
+
**Min:**
|
340
340
|
`min` returns the smallest value of a collection of numbers.
|
341
341
|
|
342
342
|
```ruby
|
@@ -345,7 +345,7 @@ end
|
|
345
345
|
[1,2,3].min #=> 1
|
346
346
|
```
|
347
347
|
|
348
|
-
|
348
|
+
**Mean:**
|
349
349
|
`mean` and `average` returns the average of a collection of numbers.
|
350
350
|
|
351
351
|
```ruby
|
@@ -354,7 +354,7 @@ end
|
|
354
354
|
[1,2,3].mean #=> 2
|
355
355
|
```
|
356
356
|
|
357
|
-
|
357
|
+
**Median:**
|
358
358
|
`median` returns the middle value of a collection of numbers.
|
359
359
|
|
360
360
|
```ruby
|
@@ -364,7 +364,7 @@ end
|
|
364
364
|
[1,2,3,6].median #=> 2.5
|
365
365
|
```
|
366
366
|
|
367
|
-
|
367
|
+
**Mode:**
|
368
368
|
`mode` returns the most frequent value of a collection of numbers.
|
369
369
|
|
370
370
|
```ruby
|
@@ -374,7 +374,7 @@ end
|
|
374
374
|
[1,1,2,6].mode #=> 1
|
375
375
|
```
|
376
376
|
|
377
|
-
|
377
|
+
**Multiple:**
|
378
378
|
`multiple` returns the multiplication of a collection of numbers.
|
379
379
|
|
380
380
|
```ruby
|
@@ -383,7 +383,7 @@ end
|
|
383
383
|
[1,2,3].multiple #=> 6
|
384
384
|
```
|
385
385
|
|
386
|
-
|
386
|
+
**Range:**
|
387
387
|
`range` returns the difference between the smallest and largest value of a collection of numbers.
|
388
388
|
|
389
389
|
```ruby
|
@@ -392,7 +392,7 @@ end
|
|
392
392
|
[1,2,6].range #=> 5
|
393
393
|
```
|
394
394
|
|
395
|
-
|
395
|
+
**Several:**
|
396
396
|
`several?` returns if collection has more than one element while not respecting nil and false as an element.
|
397
397
|
|
398
398
|
```ruby
|
@@ -402,7 +402,7 @@ end
|
|
402
402
|
[1,1,3,3].several?(&:even?) #=> false
|
403
403
|
```
|
404
404
|
|
405
|
-
|
405
|
+
**Standard Deviation:**
|
406
406
|
`standard_deviation` returns the standard deviation of elements of a collection.
|
407
407
|
|
408
408
|
```ruby
|
@@ -411,7 +411,7 @@ end
|
|
411
411
|
[1,2,6].standard_deviation #=> 2.6457513110645907
|
412
412
|
```
|
413
413
|
|
414
|
-
|
414
|
+
**Sum:**
|
415
415
|
`sum` returns the sum of a collection of numbers.
|
416
416
|
|
417
417
|
```ruby
|
@@ -420,7 +420,7 @@ end
|
|
420
420
|
['foo', 'bar'].sum #=> 'foobar'
|
421
421
|
```
|
422
422
|
|
423
|
-
|
423
|
+
**Take Last:**
|
424
424
|
`take_last` returns the last number of elements of a collection.
|
425
425
|
|
426
426
|
```ruby
|
@@ -429,7 +429,7 @@ end
|
|
429
429
|
[1,2,3].take_last(2) #=> [2,3]
|
430
430
|
```
|
431
431
|
|
432
|
-
|
432
|
+
**Take Last If:**
|
433
433
|
`take_last_if` returns the last number of elements of a collection while it meets a criteria.
|
434
434
|
|
435
435
|
```ruby
|
@@ -438,7 +438,7 @@ end
|
|
438
438
|
[1,2,3,4].take_last_if(&:odd?) #=> []
|
439
439
|
```
|
440
440
|
|
441
|
-
|
441
|
+
**Variance:**
|
442
442
|
`variance` returns the variance of elements of a collection.
|
443
443
|
|
444
444
|
```ruby
|
@@ -449,7 +449,7 @@ end
|
|
449
449
|
|
450
450
|
## Hash
|
451
451
|
|
452
|
-
|
452
|
+
**Assert Valid Keys:**
|
453
453
|
`assert_valid_keys` and `assert_valid_keys!` raises an error if key is not included in a list of keys.
|
454
454
|
|
455
455
|
```ruby
|
@@ -459,7 +459,7 @@ end
|
|
459
459
|
{ foo: 'bar', baz: 'boz' }.assert_valid_keys(:foo, :boo) #=> raises 'ArgumentError: Unknown key: :baz. Valid keys are: :foo, :boo'
|
460
460
|
```
|
461
461
|
|
462
|
-
|
462
|
+
**Compact:**
|
463
463
|
`compact` and `compact!` returns a hash with non nil values.
|
464
464
|
|
465
465
|
```ruby
|
@@ -468,7 +468,7 @@ end
|
|
468
468
|
{ foo: 'bar', baz: false, boo: nil }.compact #=> { foo: 'bar', baz: false }
|
469
469
|
```
|
470
470
|
|
471
|
-
|
471
|
+
**Deep Merge:**
|
472
472
|
`deep_merge` and `deep_merge!` returns a new hash with self and other_hash merged recursively.
|
473
473
|
|
474
474
|
```ruby
|
@@ -478,7 +478,7 @@ h2 = { a: false, b: { x: [3, 4, 5] } }
|
|
478
478
|
h1.deep_merge(h2) #=> { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
|
479
479
|
```
|
480
480
|
|
481
|
-
|
481
|
+
**Dig:**
|
482
482
|
`dig` returns the value of a nested hash.
|
483
483
|
|
484
484
|
```ruby
|
@@ -488,7 +488,7 @@ h1.dig(:a, :b) #=> { c: :d }
|
|
488
488
|
h1.dig(:a, :b, :c) #=> :d
|
489
489
|
```
|
490
490
|
|
491
|
-
|
491
|
+
**Except:**
|
492
492
|
`except` and `except!` returns a hash that includes everything but the given keys.
|
493
493
|
|
494
494
|
```ruby
|
@@ -497,21 +497,21 @@ h1.dig(:a, :b, :c) #=> :d
|
|
497
497
|
{ :foo => 'foo', :baz => 'baz', :bar => 'bar' }.except(:baz, :bar) #=> { :foo => 'foo' }
|
498
498
|
```
|
499
499
|
|
500
|
-
|
500
|
+
**Hmap:**
|
501
501
|
`hmap` and `hmap!` returns a hash that is transformed in place.
|
502
502
|
|
503
503
|
```ruby
|
504
504
|
{ a: 1, b: 2, c: 3 }.hmap { |k, v| { k => v + 3 } } #=> { a: 4, b: 5, c: 6 }
|
505
505
|
```
|
506
506
|
|
507
|
-
|
507
|
+
**Nillify:**
|
508
508
|
`nillify` and `nillify!` transforms all blank values to nil.
|
509
509
|
|
510
510
|
```ruby
|
511
511
|
{ a: 1, b: 'test', c: nil, d: false, e: '', f: ' ' }.nillify #=> {a: 1, b: 'test', c: nil, d: nil, e: nil, f: nil}
|
512
512
|
```
|
513
513
|
|
514
|
-
|
514
|
+
**Only:**
|
515
515
|
`only` and `only!` returns only key/value pairs matching certain keys.
|
516
516
|
|
517
517
|
```ruby
|
@@ -520,7 +520,7 @@ h1.dig(:a, :b, :c) #=> :d
|
|
520
520
|
{ :foo => 'foo', :baz => 'baz', :bar => 'bar' }.only(:baz, :bar) #=> { :baz => 'baz', :bar => 'bar' }
|
521
521
|
```
|
522
522
|
|
523
|
-
|
523
|
+
**Rename Keys:**
|
524
524
|
`rename_keys` and `rename_keys!` rename the keys of a hash.
|
525
525
|
|
526
526
|
```ruby
|
@@ -528,7 +528,7 @@ h1.dig(:a, :b, :c) #=> :d
|
|
528
528
|
{ foo: 'foo', 'baz' => 'baz' }.rename_keys(foo: :bar, 'baz' => 'tick') #=> { bar: 'foo', tick: 'baz' }
|
529
529
|
```
|
530
530
|
|
531
|
-
|
531
|
+
**Reverse Merge:**
|
532
532
|
`reverse_merge` and `reverse_merge!` merges one hash into other hash.
|
533
533
|
|
534
534
|
```ruby
|
@@ -536,7 +536,7 @@ h1.dig(:a, :b, :c) #=> :d
|
|
536
536
|
{ foo: 'bar' }.reverse_merge!(baz: 'boo', boo: 'bam') #=> { foo: 'bar', baz: 'boo', boo: 'bam' }
|
537
537
|
```
|
538
538
|
|
539
|
-
|
539
|
+
**Sample:**
|
540
540
|
`sample` returns a random key-value pair.
|
541
541
|
`sample!` deletes a random key-value pair and returns that pair.
|
542
542
|
|
@@ -547,7 +547,7 @@ h.sample #=> [:c, 3]
|
|
547
547
|
h.sample! #=> [:a, 1]
|
548
548
|
```
|
549
549
|
|
550
|
-
|
550
|
+
**Sample Key:**
|
551
551
|
`sample_key` returns a random key.
|
552
552
|
`sample_key!` delete a random key-value pair, returning the key.
|
553
553
|
|
@@ -558,7 +558,7 @@ h.sample_key #=> :b
|
|
558
558
|
h.sample_key! #=> :d
|
559
559
|
```
|
560
560
|
|
561
|
-
|
561
|
+
**Sample Value:**
|
562
562
|
`sample_value` returns a random value.
|
563
563
|
`sample_value!` delete a random key-value pair, returning the value.
|
564
564
|
|
@@ -569,7 +569,7 @@ h.sample_value #=> 1
|
|
569
569
|
h.sample_value! #=> 3
|
570
570
|
```
|
571
571
|
|
572
|
-
|
572
|
+
**Shuffle:**
|
573
573
|
`shuffle` returns a copy of the hash with values arranged in new random order.
|
574
574
|
`shuffle!` returns the hash with values arranged in new random order.
|
575
575
|
|
@@ -580,7 +580,7 @@ h.shuffle #=> { b: 2, c: 3, a: 1, d: 4 }
|
|
580
580
|
h.shuffle! #=> { d: 4, b: 2, c: 3, a: 1 }
|
581
581
|
```
|
582
582
|
|
583
|
-
|
583
|
+
**Slice:**
|
584
584
|
`slice` a hash to include only the given keys. Returns a hash containing the given keys.
|
585
585
|
`slice!` replaces the hash with only the given keys. Returns a hash containing the removed key/value pairs.
|
586
586
|
|
@@ -591,14 +591,14 @@ h.slice(:a, :b) #=> { a: 1, b: 2 }
|
|
591
591
|
h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
592
592
|
```
|
593
593
|
|
594
|
-
|
594
|
+
**Stringify Keys:**
|
595
595
|
`stringify_keys` and `stringify_keys!` converts the hash keys to strings.
|
596
596
|
|
597
597
|
```ruby
|
598
598
|
{ foo: 'foo', 'bar' => 'bar' }.stringify_keys #=> { 'foo' => 'foo', 'baz' => 'baz' }
|
599
599
|
```
|
600
600
|
|
601
|
-
|
601
|
+
**Strip:**
|
602
602
|
`strip` and `strip!` returns a hash with non nil, false, or blank values.
|
603
603
|
|
604
604
|
```ruby
|
@@ -607,28 +607,28 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
607
607
|
{ foo: 'bar', baz: false, boo: nil, boz: '', faz: ' ' }.strip #=> { foo: 'bar' }
|
608
608
|
```
|
609
609
|
|
610
|
-
|
610
|
+
**Symbolize Keys:**
|
611
611
|
`symbolize_keys` and `symbolize_keys!` converts the hash keys to symbols.
|
612
612
|
|
613
613
|
```ruby
|
614
614
|
{ foo: 'foo', 'bar' => 'bar' }.symbolize_keys #=> { foo: 'foo', baz: 'baz' }
|
615
615
|
```
|
616
616
|
|
617
|
-
|
617
|
+
**Symbolize and Underscore Keys:**
|
618
618
|
`symbolize_and_underscore_keys` and `symbolize_and_underscore_keys!` symbolize and underscore hash keys.
|
619
619
|
|
620
620
|
```ruby
|
621
621
|
{ 'firstName' => 'foo', 'last Name' => 'test' }.symbolize_and_underscore_keys #=> { first_name: 'foo', last_name: 'test' }
|
622
622
|
```
|
623
623
|
|
624
|
-
|
624
|
+
**Transform Keys:**
|
625
625
|
`transform_keys` and `transform_keys!` a new hash with all keys converted using the block operation.
|
626
626
|
|
627
627
|
```ruby
|
628
628
|
{ foo: 'bar', baz: 'boo' }.transform_keys { |k| k.to_s.upcase } #=> { 'FOO' => 'bar', 'BAZ' => 'boo' }
|
629
629
|
```
|
630
630
|
|
631
|
-
|
631
|
+
**Transform Values:**
|
632
632
|
`transform_values` and `transform_values!` a new hash with all values converted using the block operation.
|
633
633
|
|
634
634
|
```ruby
|
@@ -637,28 +637,28 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
637
637
|
|
638
638
|
## Integer
|
639
639
|
|
640
|
-
|
640
|
+
**Factorial:**
|
641
641
|
`factorial` calculate the factorial of an integer.
|
642
642
|
|
643
643
|
```ruby
|
644
644
|
4.factorial #=> 24
|
645
645
|
```
|
646
646
|
|
647
|
-
|
647
|
+
**Of:**
|
648
648
|
`of` is like #times but returns a collection of the yield results.
|
649
649
|
|
650
650
|
```ruby
|
651
651
|
3.of { |i| '#{i+1}' } #=> ['1', '2', '3']
|
652
652
|
```
|
653
653
|
|
654
|
-
|
654
|
+
**Roman:**
|
655
655
|
`roman` converts this integer to a roman numeral.
|
656
656
|
|
657
657
|
```ruby
|
658
658
|
49.roman #=> 'XLIX'
|
659
659
|
```
|
660
660
|
|
661
|
-
|
661
|
+
**Time:**
|
662
662
|
`time` returns a Time object for the given Integer.
|
663
663
|
|
664
664
|
```ruby
|
@@ -667,42 +667,42 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
667
667
|
|
668
668
|
## Numeric
|
669
669
|
|
670
|
-
|
670
|
+
**Add:**
|
671
671
|
`add` returns the sum of two numbers.
|
672
672
|
|
673
673
|
```ruby
|
674
674
|
4.add(2) #=> 6
|
675
675
|
```
|
676
676
|
|
677
|
-
|
677
|
+
**Bytes in Bytes:**
|
678
678
|
`byte_in_bytes` and `bytes_in_bytes` returns self.
|
679
679
|
|
680
680
|
```ruby
|
681
681
|
3.bytes_in_bytes #=> 3
|
682
682
|
```
|
683
683
|
|
684
|
-
|
684
|
+
**Centigrams in Grams:**
|
685
685
|
`centigram_in_grams` and `centigrams_in_grams` returns the amount of grams in n centigrams.
|
686
686
|
|
687
687
|
```ruby
|
688
688
|
3.centigrams_in_grams #=> 0.03
|
689
689
|
```
|
690
690
|
|
691
|
-
|
691
|
+
**Centimeters in Meters:**
|
692
692
|
`centimeter_in_meters` and `centimeters_in_meters` returns the amount of meters in n centimeters.
|
693
693
|
|
694
694
|
```ruby
|
695
695
|
3.centimeters_in_meters #=> 0.03
|
696
696
|
```
|
697
697
|
|
698
|
-
|
698
|
+
**Centuries_in_seconds:**
|
699
699
|
`century_in_seconds` and `centuries_in_seconds` returns the amount of seconds in n centuries.
|
700
700
|
|
701
701
|
```ruby
|
702
702
|
3.centuries_in_seconds #=> 9467280000.0
|
703
703
|
```
|
704
704
|
|
705
|
-
|
705
|
+
**Clamp:**
|
706
706
|
`clamp` returns a comparable between a lower and upper bound.
|
707
707
|
|
708
708
|
```ruby
|
@@ -711,55 +711,55 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
711
711
|
8.clamp(3, 6) # => 6
|
712
712
|
```
|
713
713
|
|
714
|
-
|
714
|
+
**Days in Seconds:**
|
715
715
|
`day_in_seconds` and `days_in_seconds` returns the amount of seconds in n days.
|
716
716
|
|
717
717
|
```ruby
|
718
718
|
3.days_in_seconds #=> 259200
|
719
719
|
```
|
720
720
|
|
721
|
-
|
721
|
+
**Decades in Seconds:**
|
722
722
|
`decade_in_seconds` and `decades_in_seconds` returns the amount of seconds in n decades.
|
723
723
|
|
724
724
|
```ruby
|
725
725
|
3.decades_in_seconds #=> 946728000.0
|
726
726
|
```
|
727
|
-
|
727
|
+
**Decagrams in Grams:**
|
728
728
|
`decagram_in_grams` and `decagrams_in_grams` returns the amount of grams in n decagrams.
|
729
729
|
|
730
730
|
```ruby
|
731
731
|
3.decagrams_in_grams #=> 30
|
732
732
|
```
|
733
733
|
|
734
|
-
|
734
|
+
**Decameters in Meters:**
|
735
735
|
`decameter_in_meters` and `decameters_in_meters` returns the amount of meters in n decameters.
|
736
736
|
|
737
737
|
```ruby
|
738
738
|
3.decameters_in_meters #=> 30
|
739
739
|
```
|
740
740
|
|
741
|
-
|
741
|
+
**Decigrams in Grams:**
|
742
742
|
`decigram_in_grams` and `decigrams_in_grams` returns the amount of grams in n decigrams.
|
743
743
|
|
744
744
|
```ruby
|
745
745
|
3.decigrams_in_grams #=> 0.3
|
746
746
|
```
|
747
747
|
|
748
|
-
|
748
|
+
**Decimeters in Meters:**
|
749
749
|
`decimeter_in_meters` and `decimeters_in_meters` returns the amount of meters in n decimeters.
|
750
750
|
|
751
751
|
```ruby
|
752
752
|
3.decimeters_in_meters #=> 0.3
|
753
753
|
```
|
754
754
|
|
755
|
-
|
755
|
+
**degrees_to_radians:**
|
756
756
|
`degrees_to_radians` returns number of degrees into radians.
|
757
757
|
|
758
758
|
```ruby
|
759
759
|
90.degrees_to_radians #=> 1.5707963267948966
|
760
760
|
```
|
761
761
|
|
762
|
-
|
762
|
+
**Distance:**
|
763
763
|
`distance` returns the absolute difference between numbers.
|
764
764
|
|
765
765
|
```ruby
|
@@ -767,42 +767,42 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
767
767
|
3.distance(5) #=> 2
|
768
768
|
```
|
769
769
|
|
770
|
-
|
770
|
+
**Divide:**
|
771
771
|
`divide` returns the division of two numbers.
|
772
772
|
|
773
773
|
```ruby
|
774
774
|
4.divide(2) #=> 2
|
775
775
|
```
|
776
776
|
|
777
|
-
|
777
|
+
**Exabytes in Bytes:**
|
778
778
|
`exabyte_in_bytes` and `exabytes_in_bytes` returns the amount of bytes in n exabytes.
|
779
779
|
|
780
780
|
```ruby
|
781
781
|
3.exabytes_in_bytes #=> 3458764513820540928
|
782
782
|
```
|
783
783
|
|
784
|
-
|
784
|
+
**Feet in Inches:**
|
785
785
|
`foot_in_inches` and `feet_in_inches` returns the amount of inches in n feet.
|
786
786
|
|
787
787
|
```ruby
|
788
788
|
3.feet_in_inches #=> 36
|
789
789
|
```
|
790
790
|
|
791
|
-
|
791
|
+
**Gigabytes in Bytes:**
|
792
792
|
`gigabyte_in_bytes` and `gigabytes_in_bytes` returns the amount of bytes in n gigabytes.
|
793
793
|
|
794
794
|
```ruby
|
795
795
|
3.gigabytes_in_bytes #=> 3221225472
|
796
796
|
```
|
797
797
|
|
798
|
-
|
798
|
+
**Grams in Grams:**
|
799
799
|
`gram_in_grams` and `grams_in_grams` returns self.
|
800
800
|
|
801
801
|
```ruby
|
802
802
|
3.grams_in_grams #=> 3
|
803
803
|
```
|
804
804
|
|
805
|
-
|
805
|
+
**Greater Than:**
|
806
806
|
`greater_than?` returns true if self is greater than n.
|
807
807
|
|
808
808
|
```ruby
|
@@ -811,7 +811,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
811
811
|
3.greater_than?(4) #=> false
|
812
812
|
```
|
813
813
|
|
814
|
-
|
814
|
+
**Greater Than or Equal To:**
|
815
815
|
`greater_than_or_equal_to?` returns true if self is greater than or equal to n.
|
816
816
|
|
817
817
|
```ruby
|
@@ -820,35 +820,35 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
820
820
|
3.greater_than_or_equal_to?(4) #=> false
|
821
821
|
```
|
822
822
|
|
823
|
-
|
823
|
+
**Hectograms in Grams:**
|
824
824
|
`hectogram_in_grams` and `hectograms_in_grams` returns the amount of grams in n hectograms.
|
825
825
|
|
826
826
|
```ruby
|
827
827
|
3.hectograms_in_grams #=> 300
|
828
828
|
```
|
829
829
|
|
830
|
-
|
830
|
+
**Hectometers in Meters:**
|
831
831
|
`hectometer_in_meters` and `hectometers_in_meters` returns the amount of meters in n hectometers.
|
832
832
|
|
833
833
|
```ruby
|
834
834
|
3.hectometers_in_meters #=> 300
|
835
835
|
```
|
836
836
|
|
837
|
-
|
837
|
+
**Hours in Seconds:**
|
838
838
|
`hour_in_seconds` and `hours_in_seconds` returns the amount of seconds in n hours.
|
839
839
|
|
840
840
|
```ruby
|
841
841
|
3.hours_in_seconds #=> 10800
|
842
842
|
```
|
843
843
|
|
844
|
-
|
844
|
+
**Inches in Inches:**
|
845
845
|
`inch_in_inches` and `inches_in_inches` returns the amount of inches in n inches.
|
846
846
|
|
847
847
|
```ruby
|
848
848
|
3.inches_in_inches #=> 3
|
849
849
|
```
|
850
850
|
|
851
|
-
|
851
|
+
**Inside:**
|
852
852
|
`inside?` returns true if n is greater than start and less than finish. Similar to between but does not return true if equal to self.
|
853
853
|
|
854
854
|
```ruby
|
@@ -856,28 +856,28 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
856
856
|
3.inside?(3, 5) #=> false
|
857
857
|
```
|
858
858
|
|
859
|
-
|
859
|
+
**Kilobytes in Bytes:**
|
860
860
|
`kilobyte_in_bytes` and `kilobytes_in_bytes` returns the amount of bytes in n kilobytes.
|
861
861
|
|
862
862
|
```ruby
|
863
863
|
3.kilobytes_in_bytes #=> 3072
|
864
864
|
```
|
865
865
|
|
866
|
-
|
866
|
+
**Kilograms in Grams:**
|
867
867
|
`kilogram_in_grams` and `kilograms_in_grams` returns the amount of grams in n kilograms.
|
868
868
|
|
869
869
|
```ruby
|
870
870
|
3.kilograms_in_grams #=> 3000
|
871
871
|
```
|
872
872
|
|
873
|
-
|
873
|
+
**Kilometers in Meters:**
|
874
874
|
`kilometer_in_meters` and `kilometers_in_meters` returns the amount of meters in n kilometers.
|
875
875
|
|
876
876
|
```ruby
|
877
877
|
3.kilometers_in_meters #=> 3000
|
878
878
|
```
|
879
879
|
|
880
|
-
|
880
|
+
**Less Than:**
|
881
881
|
`less_than?` returns true if self is less than n.
|
882
882
|
|
883
883
|
```ruby
|
@@ -886,7 +886,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
886
886
|
3.less_than?(4) #=> true
|
887
887
|
```
|
888
888
|
|
889
|
-
|
889
|
+
**Less Than or Equal To:**
|
890
890
|
`less_than_or_equal_to?` returns true if self is less than or equal to n.
|
891
891
|
|
892
892
|
```ruby
|
@@ -895,70 +895,70 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
895
895
|
3.less_than_or_equal_to?(4) #=> true
|
896
896
|
```
|
897
897
|
|
898
|
-
|
898
|
+
**Metric Ton in Ounces:**
|
899
899
|
`metric_ton_in_ounces` and `metric_tons_in_ounces` returns the amount of grams in n metric_tons.
|
900
900
|
|
901
901
|
```ruby
|
902
902
|
3.metric_tons_in_ounces #=> 3000000
|
903
903
|
```
|
904
904
|
|
905
|
-
|
905
|
+
**Megabytes in Bytes:**
|
906
906
|
`megabyte_in_bytes` and `megabytes_in_bytes` returns the amount of bytes in n megabytes.
|
907
907
|
|
908
908
|
```ruby
|
909
909
|
3.megabytes_in_bytes #=> 3145728
|
910
910
|
```
|
911
911
|
|
912
|
-
|
912
|
+
**Meters in Meters:**
|
913
913
|
`meter_in_meters` and `meters_in_meters` returns self.
|
914
914
|
|
915
915
|
```ruby
|
916
916
|
3.meters_in_meters #=> 3
|
917
917
|
```
|
918
918
|
|
919
|
-
|
919
|
+
**Miles in Inches:**
|
920
920
|
`mile_in_inches` and `miles_in_inches` returns the amount of inches in n miles.
|
921
921
|
|
922
922
|
```ruby
|
923
923
|
3.miles_in_inches #=> 190080
|
924
924
|
```
|
925
925
|
|
926
|
-
|
926
|
+
**Millenniums in Seconds:**
|
927
927
|
`millennium_in_seconds` and `millenniums_in_seconds` returns the amount of seconds in n millenniums.
|
928
928
|
|
929
929
|
```ruby
|
930
930
|
3.millenniums_in_seconds #=> 94672800000.0
|
931
931
|
```
|
932
932
|
|
933
|
-
|
933
|
+
**Milligrams in Grams:**
|
934
934
|
`milligram_in_grams` and `milligrams_in_grams` returns the amount of grams in n milligrams.
|
935
935
|
|
936
936
|
```ruby
|
937
937
|
3.milligrams_in_grams #=> 0.003
|
938
938
|
```
|
939
939
|
|
940
|
-
|
940
|
+
**Millimeters in Meters:**
|
941
941
|
`millimeter_in_meters` and `millimeters_in_meters` returns the amount of meters in n millimeters.
|
942
942
|
|
943
943
|
```ruby
|
944
944
|
3.millimeters_in_meters #=> 0.003
|
945
945
|
```
|
946
946
|
|
947
|
-
|
947
|
+
**Minutes in Seconds:**
|
948
948
|
`minute_in_seconds` and `minutes_in_seconds` returns the amount of seconds in n minutes.
|
949
949
|
|
950
950
|
```ruby
|
951
951
|
3.minutes_in_seconds #=> 180
|
952
952
|
```
|
953
953
|
|
954
|
-
|
954
|
+
**Multiply:**
|
955
955
|
`multiply` returns the multiplication of two numbers.
|
956
956
|
|
957
957
|
```ruby
|
958
958
|
4.multiply(2) #=> 8
|
959
959
|
```
|
960
960
|
|
961
|
-
|
961
|
+
**Multiple Of:**
|
962
962
|
`multiple_of?` returns true if a number can be evenly divided by n.
|
963
963
|
|
964
964
|
```ruby
|
@@ -966,14 +966,14 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
966
966
|
7.multiple_of?(3) #=> false
|
967
967
|
```
|
968
968
|
|
969
|
-
|
969
|
+
**Nautical Miles in Inches:**
|
970
970
|
`nautical_mile_in_inches` and `nautical_miles_in_inches` returns the amount of inches in n nautical miles.
|
971
971
|
|
972
972
|
```ruby
|
973
973
|
3.nautical_miles_in_inches #=> 218740.26239999998
|
974
974
|
```
|
975
975
|
|
976
|
-
|
976
|
+
**Negative:**
|
977
977
|
`negative?` returns true if a number is less than zero.
|
978
978
|
|
979
979
|
```ruby
|
@@ -981,7 +981,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
981
981
|
1.negative? #=> false
|
982
982
|
```
|
983
983
|
|
984
|
-
|
984
|
+
**Ordinal:**
|
985
985
|
`ordinal` returns the suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
|
986
986
|
|
987
987
|
```ruby
|
@@ -991,7 +991,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
991
991
|
'11'.ordinal #=> 'th'
|
992
992
|
```
|
993
993
|
|
994
|
-
|
994
|
+
**Ordinalize:**
|
995
995
|
`ordinalize` transforms a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
|
996
996
|
|
997
997
|
```ruby
|
@@ -1001,14 +1001,14 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
1001
1001
|
'11'.ordinalize #=> '4th'
|
1002
1002
|
```
|
1003
1003
|
|
1004
|
-
|
1004
|
+
**Ounces in Ounces:**
|
1005
1005
|
`ounce_in_ounces` and `ounces_in_ounces` returns self.
|
1006
1006
|
|
1007
1007
|
```ruby
|
1008
1008
|
3.ounces_in_ounces #=> 48
|
1009
1009
|
```
|
1010
1010
|
|
1011
|
-
|
1011
|
+
**Outside:**
|
1012
1012
|
`outside?` returns true if n is less than start or greater than finish.
|
1013
1013
|
|
1014
1014
|
```ruby
|
@@ -1016,7 +1016,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
1016
1016
|
3.outside?(3, 5) #=> false
|
1017
1017
|
```
|
1018
1018
|
|
1019
|
-
|
1019
|
+
**Pad:**
|
1020
1020
|
`pad` returns a string reprensentation of the number padded with pad_num to a specified length.
|
1021
1021
|
|
1022
1022
|
```ruby
|
@@ -1025,7 +1025,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
1025
1025
|
3.pad(precision: 4) #=> '0003'
|
1026
1026
|
```
|
1027
1027
|
|
1028
|
-
|
1028
|
+
**Pad Precision:**
|
1029
1029
|
`pad_precision` returns a string of padded after the '.' to n amount.
|
1030
1030
|
|
1031
1031
|
**Options**
|
@@ -1039,14 +1039,14 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
1039
1039
|
3.pad_precision(pad_number: 1) #=> '3.11'
|
1040
1040
|
```
|
1041
1041
|
|
1042
|
-
|
1042
|
+
**Petabytes in Bytes:**
|
1043
1043
|
`petabyte_in_bytes` and `pegabytes_in_bytes` returns the amount of bytes in n petabytes.
|
1044
1044
|
|
1045
1045
|
```ruby
|
1046
1046
|
3.petabytes_in_bytes #=> 3377699720527872
|
1047
1047
|
```
|
1048
1048
|
|
1049
|
-
|
1049
|
+
**Positive:**
|
1050
1050
|
`positive?` returns true if a number is greater than zero.
|
1051
1051
|
|
1052
1052
|
```ruby
|
@@ -1054,56 +1054,56 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
1054
1054
|
-1.positive? #=> false
|
1055
1055
|
```
|
1056
1056
|
|
1057
|
-
|
1057
|
+
**Pounds in Ounces:**
|
1058
1058
|
`pound_in_ounces` and `pounds_in_ounces` returns the amount of ounces in n pounds.
|
1059
1059
|
|
1060
1060
|
```ruby
|
1061
1061
|
3.pounds_in_ounces #=> 48
|
1062
1062
|
```
|
1063
1063
|
|
1064
|
-
|
1064
|
+
**Power:**
|
1065
1065
|
`power` returns the nth power of a number.
|
1066
1066
|
|
1067
1067
|
```ruby
|
1068
1068
|
4.power(2) #=> 16
|
1069
1069
|
```
|
1070
1070
|
|
1071
|
-
|
1071
|
+
**Root:**
|
1072
1072
|
`root` returns the nth root of a number.
|
1073
1073
|
|
1074
1074
|
```ruby
|
1075
1075
|
4.root(2) #=> 2
|
1076
1076
|
```
|
1077
1077
|
|
1078
|
-
|
1078
|
+
**Seconds in Seconds:**
|
1079
1079
|
`second_in_seconds` and `seconds_in_seconds` returns self.
|
1080
1080
|
|
1081
1081
|
```ruby
|
1082
1082
|
3.seconds #=> 3
|
1083
1083
|
```
|
1084
1084
|
|
1085
|
-
|
1085
|
+
**Stones in Ounces:**
|
1086
1086
|
`stone_in_ounces` and `stone_in_ounces` returns the amount of ounces in n stones.
|
1087
1087
|
|
1088
1088
|
```ruby
|
1089
1089
|
3.stones_in_ounces #=> 672
|
1090
1090
|
```
|
1091
1091
|
|
1092
|
-
|
1092
|
+
**Subtract:**
|
1093
1093
|
`subtract` returns the difference of two numbers.
|
1094
1094
|
|
1095
1095
|
```ruby
|
1096
1096
|
4.subtract(2) #=> 2
|
1097
1097
|
```
|
1098
1098
|
|
1099
|
-
|
1099
|
+
**Terabytes in Bytes:**
|
1100
1100
|
`terabyte_in_bytes` and `terabytes_in_bytes` returns the amount of bytes in n terabytes.
|
1101
1101
|
|
1102
1102
|
```ruby
|
1103
1103
|
3.terabytes_in_bytes #=> 3298534883328
|
1104
1104
|
```
|
1105
1105
|
|
1106
|
-
|
1106
|
+
**To Byte:**
|
1107
1107
|
`to_byte_in_bytes` converts a byte size from one unit to another unit.
|
1108
1108
|
|
1109
1109
|
```ruby
|
@@ -1113,7 +1113,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
1113
1113
|
80.to_byte(:megabyte, :gigabyte) #=> 0.078125 #GB
|
1114
1114
|
```
|
1115
1115
|
|
1116
|
-
|
1116
|
+
**To Currency:**
|
1117
1117
|
`to_currency` converts a number to currency string.
|
1118
1118
|
|
1119
1119
|
**Options**
|
@@ -1128,7 +1128,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
1128
1128
|
3.to_currency(unit: '@') #=> '@3.00'
|
1129
1129
|
```
|
1130
1130
|
|
1131
|
-
|
1131
|
+
**To Length:**
|
1132
1132
|
`to_length` converts a length from one unit to another unit.
|
1133
1133
|
|
1134
1134
|
```ruby
|
@@ -1138,7 +1138,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
1138
1138
|
1.to_length(:kilometer, :yards) #=> 1093.6138888888888 #YDS
|
1139
1139
|
```
|
1140
1140
|
|
1141
|
-
|
1141
|
+
**To Mass:**
|
1142
1142
|
`to_mass` converts a mass from one unit to another unit.
|
1143
1143
|
|
1144
1144
|
```ruby
|
@@ -1148,7 +1148,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
1148
1148
|
1.to_mass(:kilograms, :pounds) #=> 2.204625 #LB
|
1149
1149
|
```
|
1150
1150
|
|
1151
|
-
|
1151
|
+
**To Nearest Value:**
|
1152
1152
|
`to_nearest value` return the value in values that is nearest to the number.
|
1153
1153
|
|
1154
1154
|
```ruby
|
@@ -1156,7 +1156,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
1156
1156
|
3.5.to_nearest_value([3.0, 3.3, 3.6, 3.9]) #=> 3.6
|
1157
1157
|
```
|
1158
1158
|
|
1159
|
-
|
1159
|
+
**To Percantage:**
|
1160
1160
|
`to_percentage` converts a number to percentage string.
|
1161
1161
|
|
1162
1162
|
**Options**
|
@@ -1171,7 +1171,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
1171
1171
|
3.to_percentage(unit: '@') #=> '3.00@'
|
1172
1172
|
```
|
1173
1173
|
|
1174
|
-
|
1174
|
+
**To Temperature:**
|
1175
1175
|
`to_temperature` converts a temperature from one unit to another unit.
|
1176
1176
|
|
1177
1177
|
```ruby
|
@@ -1180,7 +1180,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
1180
1180
|
212.to_temperature(:fahrenheit, :kelvin) #=> 373.15 #K
|
1181
1181
|
```
|
1182
1182
|
|
1183
|
-
|
1183
|
+
**To Time:**
|
1184
1184
|
`to_time` converts a time unit from one unit to another unit.
|
1185
1185
|
|
1186
1186
|
```ruby
|
@@ -1190,35 +1190,35 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
1190
1190
|
1825.to_time(:days, :years) #=> 4.996577686516085 #YR
|
1191
1191
|
```
|
1192
1192
|
|
1193
|
-
|
1193
|
+
**Tons in Ounces:**
|
1194
1194
|
`ton_in_ounces` and `ton_in_ounces` returns the amount of ounces in n tons.
|
1195
1195
|
|
1196
1196
|
```ruby
|
1197
1197
|
3.tons_in_ounces #=> 96000
|
1198
1198
|
```
|
1199
1199
|
|
1200
|
-
|
1200
|
+
**Weeks in Seconds:**
|
1201
1201
|
`week_in_seconds` and `weeks_in_seconds` returns the amount of seconds in n weeks.
|
1202
1202
|
|
1203
1203
|
```ruby
|
1204
1204
|
3.weeks_in_seconds #=> 1814400
|
1205
1205
|
```
|
1206
1206
|
|
1207
|
-
|
1207
|
+
**Within:**
|
1208
1208
|
`within?` determines if another number is approximately equal within a given epsilon
|
1209
1209
|
|
1210
1210
|
```ruby
|
1211
1211
|
10.006.within?(10, 0.1) #=> true
|
1212
1212
|
```
|
1213
1213
|
|
1214
|
-
|
1214
|
+
**Yards in Inches:**
|
1215
1215
|
`yard_in_inches` and `yards_in_inches` returns the amount of inches in n yards.
|
1216
1216
|
|
1217
1217
|
```ruby
|
1218
1218
|
3.yards_in_inches #=> 108
|
1219
1219
|
```
|
1220
1220
|
|
1221
|
-
|
1221
|
+
**Years in Seconds:**
|
1222
1222
|
`year_in_seconds` and `years_in_seconds` returns the amount of seconds in n years.
|
1223
1223
|
|
1224
1224
|
```ruby
|
@@ -1227,7 +1227,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
1227
1227
|
|
1228
1228
|
## Object
|
1229
1229
|
|
1230
|
-
|
1230
|
+
**Array:**
|
1231
1231
|
`array?` determines if an object is an array.
|
1232
1232
|
|
1233
1233
|
```ruby
|
@@ -1235,7 +1235,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
1235
1235
|
'Awesome Sting'.array? #=> false
|
1236
1236
|
```
|
1237
1237
|
|
1238
|
-
|
1238
|
+
**Blank:**
|
1239
1239
|
`blank?` determines if an object is empty or nil.
|
1240
1240
|
|
1241
1241
|
```ruby
|
@@ -1243,7 +1243,7 @@ h.slice!(:a, :b) #=> { c: 3, d: 4 }
|
|
1243
1243
|
'Awesome Sting'.blank? #=> false
|
1244
1244
|
```
|
1245
1245
|
|
1246
|
-
|
1246
|
+
**Boolean:**
|
1247
1247
|
`boolean?` determines if an object is an boolean.
|
1248
1248
|
|
1249
1249
|
```ruby
|
@@ -1252,7 +1252,7 @@ false.boolean? #=> true
|
|
1252
1252
|
'foo'.boolean? #=> false
|
1253
1253
|
```
|
1254
1254
|
|
1255
|
-
|
1255
|
+
**False:**
|
1256
1256
|
`false?` determines if an object is false.
|
1257
1257
|
|
1258
1258
|
```ruby
|
@@ -1260,7 +1260,7 @@ false.false? #=> true
|
|
1260
1260
|
true.false? #=> false
|
1261
1261
|
```
|
1262
1262
|
|
1263
|
-
|
1263
|
+
**Falsey:**
|
1264
1264
|
`falsey?` determines if an object is false, nil, or 0.
|
1265
1265
|
|
1266
1266
|
```ruby
|
@@ -1269,7 +1269,7 @@ true.falsey? #=> false
|
|
1269
1269
|
0.falsey? #=> true
|
1270
1270
|
```
|
1271
1271
|
|
1272
|
-
|
1272
|
+
**Float:**
|
1273
1273
|
`float?` determines if an object is a float.
|
1274
1274
|
|
1275
1275
|
```ruby
|
@@ -1277,7 +1277,7 @@ true.falsey? #=> false
|
|
1277
1277
|
1.float? #=> false
|
1278
1278
|
```
|
1279
1279
|
|
1280
|
-
|
1280
|
+
**Hash:**
|
1281
1281
|
`hash?` determines if an object is a hash.
|
1282
1282
|
|
1283
1283
|
```ruby
|
@@ -1285,7 +1285,7 @@ true.falsey? #=> false
|
|
1285
1285
|
[].hash? #=> false
|
1286
1286
|
```
|
1287
1287
|
|
1288
|
-
|
1288
|
+
**Integer:**
|
1289
1289
|
`integer?` determines if an object is a integer.
|
1290
1290
|
|
1291
1291
|
```ruby
|
@@ -1293,7 +1293,7 @@ true.falsey? #=> false
|
|
1293
1293
|
1.0.integer? #=> false
|
1294
1294
|
```
|
1295
1295
|
|
1296
|
-
|
1296
|
+
**Numeric:**
|
1297
1297
|
`numeric?` determines if an object is numeric.
|
1298
1298
|
|
1299
1299
|
```ruby
|
@@ -1302,7 +1302,7 @@ true.falsey? #=> false
|
|
1302
1302
|
'1.0'.numeric? #=> false
|
1303
1303
|
```
|
1304
1304
|
|
1305
|
-
|
1305
|
+
**Numeral:**
|
1306
1306
|
`numeral?` determines if an object's string value is numeral.
|
1307
1307
|
|
1308
1308
|
```ruby
|
@@ -1310,7 +1310,7 @@ true.falsey? #=> false
|
|
1310
1310
|
'$2.55'.numeral? #=> false
|
1311
1311
|
```
|
1312
1312
|
|
1313
|
-
|
1313
|
+
**Palindrome:**
|
1314
1314
|
`palindrome?` determines if an object is equal when reversed.
|
1315
1315
|
|
1316
1316
|
```ruby
|
@@ -1320,7 +1320,7 @@ true.falsey? #=> false
|
|
1320
1320
|
12345.palindrome? #=> false
|
1321
1321
|
```
|
1322
1322
|
|
1323
|
-
|
1323
|
+
**Present:**
|
1324
1324
|
`present?` determines if an object is not empty or nil.
|
1325
1325
|
|
1326
1326
|
```ruby
|
@@ -1328,7 +1328,7 @@ true.falsey? #=> false
|
|
1328
1328
|
''.present? #=> false
|
1329
1329
|
```
|
1330
1330
|
|
1331
|
-
|
1331
|
+
**Range:**
|
1332
1332
|
`range?` determines if an object is a range.
|
1333
1333
|
|
1334
1334
|
```ruby
|
@@ -1336,7 +1336,7 @@ true.falsey? #=> false
|
|
1336
1336
|
1.range? #=> false
|
1337
1337
|
```
|
1338
1338
|
|
1339
|
-
|
1339
|
+
**Salvage:**
|
1340
1340
|
`salvage` returns a placeholder if object is blank?.
|
1341
1341
|
|
1342
1342
|
```ruby
|
@@ -1345,7 +1345,16 @@ nil.salvage('bar') #=> 'bar'
|
|
1345
1345
|
123.salvage #=> 123
|
1346
1346
|
```
|
1347
1347
|
|
1348
|
-
|
1348
|
+
**Send Chain:**
|
1349
|
+
`send_chain` chains multiple callers to an object.
|
1350
|
+
|
1351
|
+
```ruby
|
1352
|
+
3.send_chain(:factorial) #=> 6
|
1353
|
+
3.send_chain([:add, 4]) #=> 7
|
1354
|
+
3.send_chain(:factorial, [:add, 4]) #=> 10
|
1355
|
+
```
|
1356
|
+
|
1357
|
+
**String:**
|
1349
1358
|
`string?` determines if an object is a string.
|
1350
1359
|
|
1351
1360
|
```ruby
|
@@ -1353,7 +1362,7 @@ nil.salvage('bar') #=> 'bar'
|
|
1353
1362
|
1.string? #=> false
|
1354
1363
|
```
|
1355
1364
|
|
1356
|
-
|
1365
|
+
**Time:**
|
1357
1366
|
`time?` determines if an object is a time.
|
1358
1367
|
|
1359
1368
|
```ruby
|
@@ -1361,7 +1370,7 @@ Time.now.time? #=> true
|
|
1361
1370
|
'foo'.time? #=> false
|
1362
1371
|
```
|
1363
1372
|
|
1364
|
-
|
1373
|
+
**True:**
|
1365
1374
|
`true?` determines if an object is true.
|
1366
1375
|
|
1367
1376
|
```ruby
|
@@ -1369,7 +1378,7 @@ true.true? #=> true
|
|
1369
1378
|
false.true? #=> false
|
1370
1379
|
```
|
1371
1380
|
|
1372
|
-
|
1381
|
+
**Truthy:**
|
1373
1382
|
`truthy?` determines if an object is true or 1.
|
1374
1383
|
|
1375
1384
|
```ruby
|
@@ -1378,7 +1387,7 @@ false.truthy? #=> false
|
|
1378
1387
|
1.truthy? #=> true
|
1379
1388
|
```
|
1380
1389
|
|
1381
|
-
|
1390
|
+
**Try:**
|
1382
1391
|
`try` and `try!` invokes the public method whose name goes as first argument just like public_send does, except that if the receiver does not respond to it the call returns nil rather than raising an exception.
|
1383
1392
|
|
1384
1393
|
```ruby
|
@@ -1388,14 +1397,14 @@ false.truthy? #=> false
|
|
1388
1397
|
|
1389
1398
|
## Range
|
1390
1399
|
|
1391
|
-
|
1400
|
+
**Combine:**
|
1392
1401
|
`combine` returns two concated ranges.
|
1393
1402
|
|
1394
1403
|
```ruby
|
1395
1404
|
(1..3).combine(7..9) #=> [1, 2, 3, 7, 8, 9]
|
1396
1405
|
```
|
1397
1406
|
|
1398
|
-
|
1407
|
+
**Include With Range:**
|
1399
1408
|
`include_with_range?` determines if a range includes another range.
|
1400
1409
|
|
1401
1410
|
```ruby
|
@@ -1404,7 +1413,7 @@ false.truthy? #=> false
|
|
1404
1413
|
(1..5).include?(2..6) # => false
|
1405
1414
|
```
|
1406
1415
|
|
1407
|
-
|
1416
|
+
**Overlaps:**
|
1408
1417
|
`overlaps?` determines if two ranges overlap each other.
|
1409
1418
|
|
1410
1419
|
```ruby
|
@@ -1412,14 +1421,14 @@ false.truthy? #=> false
|
|
1412
1421
|
(1..5).overlaps?(7..9) # => false
|
1413
1422
|
```
|
1414
1423
|
|
1415
|
-
|
1424
|
+
**Sample:**
|
1416
1425
|
`sample` returns a random element from the range.
|
1417
1426
|
|
1418
1427
|
```ruby
|
1419
1428
|
(1..5).sample # => 4
|
1420
1429
|
```
|
1421
1430
|
|
1422
|
-
|
1431
|
+
**Shuffle:**
|
1423
1432
|
`shuffle` returns a copy of a shuffled range of elements.
|
1424
1433
|
`shuffle!` returns a shuffled range of elements.
|
1425
1434
|
|
@@ -1428,7 +1437,7 @@ false.truthy? #=> false
|
|
1428
1437
|
(1..5).shuffle! # => [3, 4, 5, 2, 1]
|
1429
1438
|
```
|
1430
1439
|
|
1431
|
-
|
1440
|
+
**Within:**
|
1432
1441
|
`within?` determines if one range is within another.
|
1433
1442
|
|
1434
1443
|
```ruby
|
@@ -1438,7 +1447,7 @@ false.truthy? #=> false
|
|
1438
1447
|
|
1439
1448
|
## String
|
1440
1449
|
|
1441
|
-
|
1450
|
+
**Any:**
|
1442
1451
|
`any?` determines if a string includes a set of string(s).
|
1443
1452
|
|
1444
1453
|
```ruby
|
@@ -1446,7 +1455,7 @@ false.truthy? #=> false
|
|
1446
1455
|
'example string'.any?('foo', 'string') #=> true
|
1447
1456
|
```
|
1448
1457
|
|
1449
|
-
|
1458
|
+
**At:**
|
1450
1459
|
`at` returns the characters at index position, matching string, or regex.
|
1451
1460
|
|
1452
1461
|
```ruby
|
@@ -1458,7 +1467,7 @@ false.truthy? #=> false
|
|
1458
1467
|
'example_string'.at(99) #=> nil
|
1459
1468
|
```
|
1460
1469
|
|
1461
|
-
|
1470
|
+
**Camelize:**
|
1462
1471
|
`camelize` and `camelize!` transfroms a string to camelcase.
|
1463
1472
|
|
1464
1473
|
```ruby
|
@@ -1468,7 +1477,7 @@ false.truthy? #=> false
|
|
1468
1477
|
'example_String'.camecase(:lower) #=> 'exampleString'
|
1469
1478
|
```
|
1470
1479
|
|
1471
|
-
|
1480
|
+
**Classify:**
|
1472
1481
|
`classify` and `classify!` creates a class name from a string like Rails does for table names to models.
|
1473
1482
|
|
1474
1483
|
```ruby
|
@@ -1477,21 +1486,21 @@ false.truthy? #=> false
|
|
1477
1486
|
'example_string.test'.classify #=> 'Test'
|
1478
1487
|
```
|
1479
1488
|
|
1480
|
-
|
1489
|
+
**Constantize:**
|
1481
1490
|
`constantize` converts a string in an object.
|
1482
1491
|
|
1483
1492
|
```ruby
|
1484
1493
|
'Example::String'.constantize #=> Class Object
|
1485
1494
|
```
|
1486
1495
|
|
1487
|
-
|
1496
|
+
**Dasherize:**
|
1488
1497
|
`dasherize` and `dasherize!` replaces underscores with dashes in the string.
|
1489
1498
|
|
1490
1499
|
```ruby
|
1491
1500
|
'example_string'.dasherize #=> 'example-string'
|
1492
1501
|
```
|
1493
1502
|
|
1494
|
-
|
1503
|
+
**Deconstantize:**
|
1495
1504
|
`deconstantize` and `deconstantize!` removes the rightmost segment from the constant expression in the string.
|
1496
1505
|
|
1497
1506
|
```ruby
|
@@ -1502,7 +1511,7 @@ false.truthy? #=> false
|
|
1502
1511
|
''.deconstantize # => ''
|
1503
1512
|
```
|
1504
1513
|
|
1505
|
-
|
1514
|
+
**Demodulize:**
|
1506
1515
|
`demodulize` and `demodulize!` removes the module part from the expression in the string.
|
1507
1516
|
|
1508
1517
|
```ruby
|
@@ -1510,7 +1519,7 @@ false.truthy? #=> false
|
|
1510
1519
|
'String'.demodulize #=> 'String'
|
1511
1520
|
```
|
1512
1521
|
|
1513
|
-
|
1522
|
+
**Domain:**
|
1514
1523
|
`domain` extracts the domain name from a URL.
|
1515
1524
|
|
1516
1525
|
```ruby
|
@@ -1518,7 +1527,7 @@ false.truthy? #=> false
|
|
1518
1527
|
'example string'.domain #=> 'example string'
|
1519
1528
|
```
|
1520
1529
|
|
1521
|
-
|
1530
|
+
**Downcase:**
|
1522
1531
|
`downcase?` returns true if all characters are lowercase.
|
1523
1532
|
|
1524
1533
|
```ruby
|
@@ -1527,7 +1536,7 @@ false.truthy? #=> false
|
|
1527
1536
|
'EXAMPLE'.downcase? #=> false
|
1528
1537
|
```
|
1529
1538
|
|
1530
|
-
|
1539
|
+
**Ellipsize:**
|
1531
1540
|
`ellipsize` truncate a string in the middle.
|
1532
1541
|
|
1533
1542
|
**Options**
|
@@ -1541,7 +1550,7 @@ false.truthy? #=> false
|
|
1541
1550
|
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.ellipsize(30, separator: '+++') #=> '0123+++WXYZ'
|
1542
1551
|
```
|
1543
1552
|
|
1544
|
-
|
1553
|
+
**Exclude:**
|
1545
1554
|
`exclude?` returns true if the string does not include the other string.
|
1546
1555
|
|
1547
1556
|
```ruby
|
@@ -1549,7 +1558,7 @@ false.truthy? #=> false
|
|
1549
1558
|
'example_string'.exclude?('xxx') #=> true
|
1550
1559
|
```
|
1551
1560
|
|
1552
|
-
|
1561
|
+
**First:**
|
1553
1562
|
`first` returns the first character. If a limit is supplied, returns a substring from the beginning of the string until it reaches the limit value. If the given limit is greater than or equal to the string length, returns a copy of self.
|
1554
1563
|
|
1555
1564
|
```ruby
|
@@ -1558,7 +1567,7 @@ false.truthy? #=> false
|
|
1558
1567
|
'example'.first(3) #=> 'exa'
|
1559
1568
|
```
|
1560
1569
|
|
1561
|
-
|
1570
|
+
**Format:**
|
1562
1571
|
`format` returns an interpolated string that allows for options.
|
1563
1572
|
|
1564
1573
|
```ruby
|
@@ -1567,7 +1576,7 @@ false.truthy? #=> false
|
|
1567
1576
|
'%d + %d'.format([1, 2]) #=> '1 + 2'
|
1568
1577
|
```
|
1569
1578
|
|
1570
|
-
|
1579
|
+
**From:**
|
1571
1580
|
`from` 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.
|
1572
1581
|
|
1573
1582
|
```ruby
|
@@ -1575,7 +1584,7 @@ false.truthy? #=> false
|
|
1575
1584
|
'example'.from(3) #=> 'mple'
|
1576
1585
|
```
|
1577
1586
|
|
1578
|
-
|
1587
|
+
**Humanize:**
|
1579
1588
|
`humanize` and `humanize!` transforms a string to a human readable string.
|
1580
1589
|
|
1581
1590
|
**Options**
|
@@ -1587,7 +1596,7 @@ false.truthy? #=> false
|
|
1587
1596
|
'example_string'.humanize(capitalize: false) #=> 'example string'
|
1588
1597
|
```
|
1589
1598
|
|
1590
|
-
|
1599
|
+
**Indent:**
|
1591
1600
|
`indent` and `indent!` indents the lines in the receiver.
|
1592
1601
|
|
1593
1602
|
```ruby
|
@@ -1595,7 +1604,7 @@ false.truthy? #=> false
|
|
1595
1604
|
'example'.indent(2, '\t') #=> '\t\texample'
|
1596
1605
|
```
|
1597
1606
|
|
1598
|
-
|
1607
|
+
**Index all:**
|
1599
1608
|
`index_all` returns the index values of matching patterns.
|
1600
1609
|
|
1601
1610
|
```ruby
|
@@ -1604,7 +1613,7 @@ false.truthy? #=> false
|
|
1604
1613
|
'asdfasdfasdf'.index_all(/sd/) #=> [1,5,9]
|
1605
1614
|
```
|
1606
1615
|
|
1607
|
-
|
1616
|
+
**Labelize:**
|
1608
1617
|
`labelize` and `labelize!` transforms a string to a human readable string.
|
1609
1618
|
|
1610
1619
|
```ruby
|
@@ -1613,7 +1622,7 @@ false.truthy? #=> false
|
|
1613
1622
|
'ExampleString'.labelize #=> 'Example string'
|
1614
1623
|
```
|
1615
1624
|
|
1616
|
-
|
1625
|
+
**Last:**
|
1617
1626
|
`last` returns the last character of the string. If a limit is supplied, returns a substring from the end of the string until it reaches the limit value (counting backwards). If the given limit is greater than or equal to the string length, returns a copy of self.
|
1618
1627
|
|
1619
1628
|
```ruby
|
@@ -1622,7 +1631,7 @@ false.truthy? #=> false
|
|
1622
1631
|
'example'.first(3) #=> 'ple'
|
1623
1632
|
```
|
1624
1633
|
|
1625
|
-
|
1634
|
+
**Mixcase:**
|
1626
1635
|
`mixcase?` returns true if characters are mixedcase.
|
1627
1636
|
|
1628
1637
|
```ruby
|
@@ -1631,7 +1640,7 @@ false.truthy? #=> false
|
|
1631
1640
|
'example'.mixedcase? #=> false
|
1632
1641
|
```
|
1633
1642
|
|
1634
|
-
|
1643
|
+
**Ordinal:**
|
1635
1644
|
`ordinal` returns the suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
|
1636
1645
|
|
1637
1646
|
```ruby
|
@@ -1641,7 +1650,7 @@ false.truthy? #=> false
|
|
1641
1650
|
'11'.ordinal #=> 'th'
|
1642
1651
|
```
|
1643
1652
|
|
1644
|
-
|
1653
|
+
**Ordinalize:**
|
1645
1654
|
`ordinalize` transforms a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
|
1646
1655
|
|
1647
1656
|
```ruby
|
@@ -1651,7 +1660,7 @@ false.truthy? #=> false
|
|
1651
1660
|
'11'.ordinalize #=> '4th'
|
1652
1661
|
```
|
1653
1662
|
|
1654
|
-
|
1663
|
+
**Parameterize:**
|
1655
1664
|
`parameterize` and `parameterize!` makes string suitable for a dashed url parameter string.
|
1656
1665
|
|
1657
1666
|
```ruby
|
@@ -1659,7 +1668,7 @@ false.truthy? #=> false
|
|
1659
1668
|
'example_string'.parameterize(separator: '?') #=> 'example?string'
|
1660
1669
|
```
|
1661
1670
|
|
1662
|
-
|
1671
|
+
**Pollute:**
|
1663
1672
|
`pollute` and `pollute!` pollutes the space between every letter in a string, so it will be exempt from any impending string searches.
|
1664
1673
|
|
1665
1674
|
```ruby
|
@@ -1667,21 +1676,21 @@ false.truthy? #=> false
|
|
1667
1676
|
'test'.pollute('-') #=> 't-e-s-t-'
|
1668
1677
|
```
|
1669
1678
|
|
1670
|
-
|
1679
|
+
**Pop:**
|
1671
1680
|
`pop` returns the last character of a string.
|
1672
1681
|
|
1673
1682
|
```ruby
|
1674
1683
|
'test'.pop #=> 't'
|
1675
1684
|
```
|
1676
1685
|
|
1677
|
-
|
1686
|
+
**Push:**
|
1678
1687
|
`push` concats string to self.
|
1679
1688
|
|
1680
1689
|
```ruby
|
1681
1690
|
'test'.push('er') #=> 'tester'
|
1682
1691
|
```
|
1683
1692
|
|
1684
|
-
|
1693
|
+
**Remove:**
|
1685
1694
|
`remove` and `remove!` removes every instance of a string.
|
1686
1695
|
|
1687
1696
|
```ruby
|
@@ -1691,7 +1700,7 @@ false.truthy? #=> false
|
|
1691
1700
|
'this thing that them'.remove('thing', 1..3) #=> 't that them'
|
1692
1701
|
```
|
1693
1702
|
|
1694
|
-
|
1703
|
+
**Remove Tags:**
|
1695
1704
|
`remove_tags` and `remove_tags!` removes HTML tags from a string.
|
1696
1705
|
|
1697
1706
|
```ruby
|
@@ -1700,7 +1709,7 @@ false.truthy? #=> false
|
|
1700
1709
|
'this is <b>bold</b> and <em>emphatic</em>'.strip_tags #=> 'this is bold and emphatic'
|
1701
1710
|
```
|
1702
1711
|
|
1703
|
-
|
1712
|
+
**Sample:**
|
1704
1713
|
`sample` and `sample!` deletes a random value and returns that value.
|
1705
1714
|
|
1706
1715
|
```ruby
|
@@ -1708,7 +1717,7 @@ false.truthy? #=> false
|
|
1708
1717
|
'this thing that'.sample(' thing ') #=> 'that'
|
1709
1718
|
```
|
1710
1719
|
|
1711
|
-
|
1720
|
+
**Shift:**
|
1712
1721
|
`shift` and `shift!` removes the first instance of a string.
|
1713
1722
|
|
1714
1723
|
```ruby
|
@@ -1717,7 +1726,7 @@ false.truthy? #=> false
|
|
1717
1726
|
'this thing that thing'.shift('this', 'that') #=> ' thing thing'
|
1718
1727
|
```
|
1719
1728
|
|
1720
|
-
|
1729
|
+
**Shuffle:**
|
1721
1730
|
`shuffle` and `shuffle!` randomizes the characters in a string.
|
1722
1731
|
|
1723
1732
|
```ruby
|
@@ -1725,7 +1734,7 @@ false.truthy? #=> false
|
|
1725
1734
|
'ruby rules'.sample! #=> 'rblse syru'
|
1726
1735
|
```
|
1727
1736
|
|
1728
|
-
|
1737
|
+
**Sift:**
|
1729
1738
|
`sift` and `sift!` returns a string matching any character in a pattern.
|
1730
1739
|
|
1731
1740
|
```ruby
|
@@ -1734,7 +1743,7 @@ false.truthy? #=> false
|
|
1734
1743
|
'qa2ws3ed4rf5tg6yh7uj8ik9ol'.sift([0,1,2,3,4,5,6,7,8,9]) #=> '23456789'
|
1735
1744
|
```
|
1736
1745
|
|
1737
|
-
|
1746
|
+
**Slugify:**
|
1738
1747
|
`slugify` and `slugify!` generates a permalink-style string, with odd characters removed.
|
1739
1748
|
|
1740
1749
|
```ruby
|
@@ -1743,14 +1752,14 @@ false.truthy? #=> false
|
|
1743
1752
|
'Example string @@@ test!'.slugify #=> 'example-string-test'
|
1744
1753
|
```
|
1745
1754
|
|
1746
|
-
|
1755
|
+
**Sort:**
|
1747
1756
|
`sort` and `sort!` sorts a string.
|
1748
1757
|
|
1749
1758
|
```ruby
|
1750
1759
|
'adbec'.sort #=> 'abcde'
|
1751
1760
|
```
|
1752
1761
|
|
1753
|
-
|
1762
|
+
**Squish:**
|
1754
1763
|
`squish` and `squish!` returns the string, first removing all whitespace on both ends of the string, and then changing remaining consecutive whitespace groups into one space each.
|
1755
1764
|
|
1756
1765
|
```ruby
|
@@ -1759,7 +1768,7 @@ false.truthy? #=> false
|
|
1759
1768
|
' example string '.squish #=> 'example string'
|
1760
1769
|
```
|
1761
1770
|
|
1762
|
-
|
1771
|
+
**Titleize:**
|
1763
1772
|
`titleize` and `titleize!` capitalizes each word in a string.
|
1764
1773
|
|
1765
1774
|
```ruby
|
@@ -1768,7 +1777,7 @@ false.truthy? #=> false
|
|
1768
1777
|
'ExampleString'.titleize #=> 'Example String'
|
1769
1778
|
```
|
1770
1779
|
|
1771
|
-
|
1780
|
+
**To:**
|
1772
1781
|
`to` returns a substring from the beginning of the string to the given position. If the position is negative, it is counted from the end of the string.
|
1773
1782
|
|
1774
1783
|
```ruby
|
@@ -1777,7 +1786,7 @@ false.truthy? #=> false
|
|
1777
1786
|
'example'.to(-2) #=> 'exampl'
|
1778
1787
|
```
|
1779
1788
|
|
1780
|
-
|
1789
|
+
**Truncate:**
|
1781
1790
|
`truncate` a given text after a given length if text is longer than length.
|
1782
1791
|
|
1783
1792
|
**Options**
|
@@ -1792,7 +1801,7 @@ false.truthy? #=> false
|
|
1792
1801
|
'example string'.truncate(15) #=> 'example string'
|
1793
1802
|
```
|
1794
1803
|
|
1795
|
-
|
1804
|
+
**Truncate Words:**
|
1796
1805
|
`truncate_words` truncates a given text after a given number of words.
|
1797
1806
|
|
1798
1807
|
**Options**
|
@@ -1805,7 +1814,7 @@ false.truthy? #=> false
|
|
1805
1814
|
'And they found that many people were sleeping better.'.truncate_words(5, omission: '... (continued)') #=> 'And they found that many... (continued)'
|
1806
1815
|
```
|
1807
1816
|
|
1808
|
-
|
1817
|
+
**Underscore:**
|
1809
1818
|
`underscore` and `underscore!` transforms a string to snakecase.
|
1810
1819
|
|
1811
1820
|
```ruby
|
@@ -1814,7 +1823,7 @@ false.truthy? #=> false
|
|
1814
1823
|
'ExampleString::Test'.underscore #=> 'example_string/test'
|
1815
1824
|
```
|
1816
1825
|
|
1817
|
-
|
1826
|
+
**Unpollute:**
|
1818
1827
|
`unpollute` and `unpollute!` removes the default or custom pollution character. Can also be used to remove an unwanted character.
|
1819
1828
|
|
1820
1829
|
```ruby
|
@@ -1822,7 +1831,7 @@ false.truthy? #=> false
|
|
1822
1831
|
't-e-s-t-'.unpollute #=> 'test'
|
1823
1832
|
```
|
1824
1833
|
|
1825
|
-
|
1834
|
+
**Upcase:**
|
1826
1835
|
`upcase?` returns true if all characters are uppercase.
|
1827
1836
|
|
1828
1837
|
```ruby
|
@@ -1831,7 +1840,7 @@ false.truthy? #=> false
|
|
1831
1840
|
'Example'.upcase? #=> false
|
1832
1841
|
```
|
1833
1842
|
|
1834
|
-
|
1843
|
+
**Unshift:**
|
1835
1844
|
`unshift` and `unshift!` prepends string(s) to self.
|
1836
1845
|
|
1837
1846
|
```ruby
|
@@ -1843,7 +1852,7 @@ false.truthy? #=> false
|
|
1843
1852
|
|
1844
1853
|
*Note:* also works with Date class.
|
1845
1854
|
|
1846
|
-
|
1855
|
+
**Format:**
|
1847
1856
|
`format` converts a Date or Time object to format it using a human readable string.
|
1848
1857
|
|
1849
1858
|
**Rules**
|
@@ -1886,7 +1895,7 @@ Time.now.format('month_name day, year hour:minute ampm') #=> 'January 09, 2014 0
|
|
1886
1895
|
| Time Zone - hour and minute offset | `zz` or `time_zone_offset` | %z | +09:00 |
|
1887
1896
|
| Time Zone - hour, minute and second offset | `zzz` or `time_zone_offset_full` | %z | +09:00:00 |
|
1888
1897
|
|
1889
|
-
|
1898
|
+
**To Format / Stamp:**
|
1890
1899
|
`to_format` and `stamp` converts a Date or Time object to a predefined format.
|
1891
1900
|
|
1892
1901
|
**For a full list check out the time extention file.**
|