powertools 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 +7 -0
- data/lib/range.rb +47 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ffbc936cb0b24ca1c6971392b36e29b9d964cece86ab3fbfa81b8679cf51210d
|
4
|
+
data.tar.gz: 3b6068b56d74e329a161d9baaf47fce237152fcd117cf0f61c0c03b1582faef5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 900bb0fa75ef4819b5c86e6657f24c9d425c81288361a0f5291d3af7947ab348021337a5666c6144274e91dd7b220d0c272315be7fd0d5905e39f62893ae2968
|
7
|
+
data.tar.gz: 86d7e45d7fcd32a02bca5b225c56f9ec105465f0bdb28c51aef4035c251383460073a640c185851d30beeb6130a2397b04647bb79653be592fda545762341825
|
data/lib/range.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module RangeExtensions
|
2
|
+
def each
|
3
|
+
return super if self.first <= self.last
|
4
|
+
|
5
|
+
position = self.first
|
6
|
+
while position >= self.last
|
7
|
+
yield(position)
|
8
|
+
position = position.pred
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def each(warn_on_order_error: true)
|
13
|
+
return super() if self.first <= self.last
|
14
|
+
|
15
|
+
position = self.first
|
16
|
+
prev_position = nil
|
17
|
+
while position >= self.last
|
18
|
+
# We always attempt pred before yielding.
|
19
|
+
prev_position = position.clone
|
20
|
+
begin
|
21
|
+
position = position.pred
|
22
|
+
rescue NoMethodError
|
23
|
+
if warn_on_order_error
|
24
|
+
raise ArgumentError.new "#{self.first.class}s do not support backwards iteration."
|
25
|
+
else
|
26
|
+
return super()
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
yield(prev_position)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def sort
|
35
|
+
begin
|
36
|
+
return self if self.first <= self.last
|
37
|
+
rescue NoMethodError
|
38
|
+
raise "#{self.first.class}s cannot be sorted"
|
39
|
+
end
|
40
|
+
|
41
|
+
(self.last..self.first)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class Range
|
46
|
+
prepend RangeExtensions
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: powertools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- C. Kinniburgh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-12-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: powertools@cjkinni.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/range.rb
|
20
|
+
homepage: http://github.com/cjkinni/powertools
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.2.22
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: A series of small improvements to Ruby classes
|
43
|
+
test_files: []
|