corefines 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +5 -0
- data/README.adoc +4 -2
- data/lib/corefines.rb +1 -0
- data/lib/corefines/class.rb +45 -0
- data/lib/corefines/version.rb +1 -1
- data/spec/class/descendants_spec.rb +22 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1470ef3188042ed178a8c0204e54046b3ea6a3d
|
4
|
+
data.tar.gz: 6a5e024a2f6e81e59aade31d49b09e59d3be57df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d5d5921ebd1dcbd39cd5a499ef9f82a4c4847cfdabea32df8c302db256a20cc6c1a45bf62e2923e052136ebb375a7839c598b2094830da22f488e74846edf30
|
7
|
+
data.tar.gz: 66952a116b6e578b37745a5da4275e1f913c397265ae3f51ea0047bb2ed963fa2b94016cce45c4d976577bfa5b907688799644f25fc39b3a3bad1cb2082d0ed1
|
data/CHANGELOG.adoc
CHANGED
@@ -3,6 +3,11 @@
|
|
3
3
|
:doc-base-url: http://www.rubydoc.info/github/jirutka/corefines/Corefines
|
4
4
|
:issue-uri: {repo-uri}/issues
|
5
5
|
|
6
|
+
== 1.8.0 (2015-07-06)
|
7
|
+
|
8
|
+
* Add new refinement {doc-base-url}/Class/descendants[Class#descendants].
|
9
|
+
|
10
|
+
|
6
11
|
== 1.7.0 (2015-07-05)
|
7
12
|
|
8
13
|
* Add new refinement {doc-base-url}/Enumerable/MapTo[Enumerable#map_to].
|
data/README.adoc
CHANGED
@@ -41,12 +41,12 @@ TODO
|
|
41
41
|
Add this line to your application’s Gemfile:
|
42
42
|
|
43
43
|
[source]
|
44
|
-
gem 'corefines', '~> 1.
|
44
|
+
gem 'corefines', '~> 1.8'
|
45
45
|
|
46
46
|
or to your gemspec:
|
47
47
|
|
48
48
|
[source]
|
49
|
-
s.add_runtime_dependency 'corefines', '~> 1.
|
49
|
+
s.add_runtime_dependency 'corefines', '~> 1.8'
|
50
50
|
|
51
51
|
and then execute:
|
52
52
|
|
@@ -133,6 +133,8 @@ Not ideal indeed, but probably the best of what we can achieve.
|
|
133
133
|
** {doc-base-url}/Array/Second[#second]
|
134
134
|
** {doc-base-url}/Array/Third[#third]
|
135
135
|
** {doc-base-url}/Array/Wrap[.wrap]
|
136
|
+
* {doc-base-url}/Class[Class]
|
137
|
+
** {doc-base-url}/Class/Descendants[#descendants]
|
136
138
|
* {doc-base-url}/Enumerable[Enumerable]
|
137
139
|
** {doc-base-url}/Enumerable/IndexBy[#index_by]
|
138
140
|
** {doc-base-url}/Enumerable/Many[#many?]
|
data/lib/corefines.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'corefines/support/alias_submodules'
|
2
|
+
|
3
|
+
module Corefines
|
4
|
+
module Class
|
5
|
+
##
|
6
|
+
# @!method descendants
|
7
|
+
# @example
|
8
|
+
# Integer.descendants # => [Fixnum, Bignum]
|
9
|
+
# Numeric.descendants # => [Integer, Fixnum, Float, Bignum, Rational, Complex]
|
10
|
+
#
|
11
|
+
# @return [Array<Class>] all descendants of this class.
|
12
|
+
#
|
13
|
+
module Descendants
|
14
|
+
begin
|
15
|
+
# Just try whether it raises exception...
|
16
|
+
::ObjectSpace.each_object(::Class.new) {}
|
17
|
+
|
18
|
+
refine ::Class do
|
19
|
+
def descendants
|
20
|
+
descendants = []
|
21
|
+
::ObjectSpace.each_object(singleton_class) do |klass|
|
22
|
+
descendants.unshift(klass) unless klass == self
|
23
|
+
end
|
24
|
+
descendants
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Compatibility mode for JRuby when running without option -X+O.
|
29
|
+
rescue StandardError
|
30
|
+
|
31
|
+
refine ::Class do
|
32
|
+
def descendants
|
33
|
+
descendants = []
|
34
|
+
::ObjectSpace.each_object(::Class) do |klass|
|
35
|
+
descendants.unshift(klass) if klass < self
|
36
|
+
end
|
37
|
+
descendants.uniq
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
include Support::AliasSubmodules
|
44
|
+
end
|
45
|
+
end
|
data/lib/corefines/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
describe Class do
|
2
|
+
using Corefines::Class::descendants
|
3
|
+
|
4
|
+
describe '#descendants' do
|
5
|
+
|
6
|
+
a = Class.new
|
7
|
+
b0 = Class.new(a)
|
8
|
+
b1 = Class.new(a)
|
9
|
+
c0 = Class.new(b0)
|
10
|
+
|
11
|
+
context 'when class without subclasses' do
|
12
|
+
it { expect( c0.descendants ).to be_empty }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when class with 2 generations of descendants' do
|
16
|
+
it 'returns all descendants of the class' do
|
17
|
+
expect( a.descendants ).to match_array [b0, b1, c0]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: corefines
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakub Jirutka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- Rakefile
|
111
111
|
- lib/corefines.rb
|
112
112
|
- lib/corefines/array.rb
|
113
|
+
- lib/corefines/class.rb
|
113
114
|
- lib/corefines/enumerable.rb
|
114
115
|
- lib/corefines/hash.rb
|
115
116
|
- lib/corefines/module.rb
|
@@ -123,6 +124,7 @@ files:
|
|
123
124
|
- spec/array/second_spec.rb
|
124
125
|
- spec/array/third_spec.rb
|
125
126
|
- spec/array/wrap_spec.rb
|
127
|
+
- spec/class/descendants_spec.rb
|
126
128
|
- spec/enumerable/index_by_spec.rb
|
127
129
|
- spec/enumerable/many_spec.rb
|
128
130
|
- spec/enumerable/map_send_spec.rb
|