rb_core_extensions 0.1.2 → 0.1.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 +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +23 -3
- data/lib/core_extensions/all.rb +4 -1
- data/lib/core_extensions/class.rb +40 -0
- data/lib/core_extensions/false_class.rb +23 -0
- data/lib/core_extensions/nil_class.rb +10 -1
- data/lib/core_extensions/true_class.rb +23 -0
- data/lib/core_extensions/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eaab7679a1e5cedcdfd17b5abaed34ac040d6d5f0bc7ab91e8e3d52695d78720
|
4
|
+
data.tar.gz: e61962df11083b76b1198b1762854142dd9e160d8e127fbdc6f11021d27f1d13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 889d4bb5b68918c8feaf3bf3ac4cac823f78b2899af9a0f3a7afe5f9d63fbef3c357e1da85c31bf07e893172ccaf540d70f9594ec756b0c82361a7c504f17b43
|
7
|
+
data.tar.gz: 3712ca130c9031070b2ec4d01edea3f88e8e991db450e6c3d229e39eeab21df2f34363b9a7464d66ee88970752f2ecfca4352d0d9a645954640f610b7e3ebd17
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## [0.1.3](https://github.com/shivam091/core_extensions/compare/v0.1.2...v0.1.3) - 2023-07-07
|
2
|
+
|
3
|
+
### What's new
|
4
|
+
|
5
|
+
- Added core extension methods `hierarchy`, `lineage`, and `leaf_subclasses` in `Class`
|
6
|
+
- Added extensions `to_i` and `to_b` in `TrueClass` and `FalseClass`
|
7
|
+
- Added `to_b` core ext. in `NilClass`
|
8
|
+
|
1
9
|
## [0.1.2](https://github.com/shivam091/core_extensions/compare/v0.1.1...v0.1.2) - 2023-07-06
|
2
10
|
|
3
11
|
### What's new
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -47,7 +47,7 @@ require "core_extensions/date"
|
|
47
47
|
|
48
48
|
## Extensions Provided
|
49
49
|
|
50
|
-
Below are the extension methods
|
50
|
+
Below are the extension methods provided by `rb_core_extensions`. Please refer [documentation](https://shivam091.github.io/core_extensions) for examples of how to use these methods.
|
51
51
|
|
52
52
|
### [Array](https://shivam091.github.io/core_extensions/Array.html)
|
53
53
|
|
@@ -78,10 +78,23 @@ Below are the extension methods which are provided by `rb_core_extensions`. Plea
|
|
78
78
|
#### ***core_extensions/hash/delete.rb***
|
79
79
|
1. **[`#slice!`](https://shivam091.github.io/core_extensions/Hash.html#method-i-slice-21)** - Alters the hash by keeping only specified `keys` and returns it.
|
80
80
|
|
81
|
+
### [TrueClass](https://shivam091.github.io/core_extensions/TrueClass.html)
|
82
|
+
|
83
|
+
#### ***core_extensions/true_class.rb***
|
84
|
+
1. **[`#to_i`](https://shivam091.github.io/core_extensions/TrueClass.html#method-i-to_i)** - Returns `1` if invoked on `TrueClass` instance.
|
85
|
+
2. **[`#to_b`](https://shivam091.github.io/core_extensions/TrueClass.html#method-i-to_b)** - Returns `true` if invoked on `TrueClass` instance.
|
86
|
+
|
87
|
+
### [FalseClass](https://shivam091.github.io/core_extensions/FalseClass.html)
|
88
|
+
|
89
|
+
#### ***core_extensions/false_class.rb***
|
90
|
+
1. **[`#to_i`](https://shivam091.github.io/core_extensions/FalseClass.html#method-i-to_i)** - Returns `0` if invoked on `FalseClass` instance.
|
91
|
+
2. **[`#to_b`](https://shivam091.github.io/core_extensions/FalseClass.html#method-i-to_b)** - Returns `false` if invoked on `FalseClass` instance.
|
92
|
+
|
81
93
|
### [NilClass](https://shivam091.github.io/core_extensions/NilClass.html)
|
82
94
|
|
83
|
-
|
84
|
-
1. **[`#blank?`](https://shivam091.github.io/core_extensions/NilClass.html#method-i-blank-3F)** - Returns `true`
|
95
|
+
#### ***core_extensions/nil_class.rb***
|
96
|
+
1. **[`#blank?`](https://shivam091.github.io/core_extensions/NilClass.html#method-i-blank-3F)** - Returns `true` if invoked on `NilClass` instance.
|
97
|
+
2. **[`#to_b`](https://shivam091.github.io/core_extensions/NilClass.html#method-i-to_b)** - Returns `false` if invoked on `NilClass` instance.
|
85
98
|
|
86
99
|
### [Object](https://shivam091.github.io/core_extensions/Object.html)
|
87
100
|
|
@@ -95,6 +108,13 @@ Below are the extension methods which are provided by `rb_core_extensions`. Plea
|
|
95
108
|
#### ***core_extensions/module.rb***
|
96
109
|
1. **[`#namespaces`](https://shivam091.github.io/core_extensions/Module.html#method-i-namespaces)** - Returns an `Array` with the namespaces to the current `Module`.
|
97
110
|
|
111
|
+
### [Class](https://shivam091.github.io/core_extensions/Class.html)
|
112
|
+
|
113
|
+
#### ***core_extensions/class.rb***
|
114
|
+
1. **[`#hierarchy`](https://shivam091.github.io/core_extensions/Class.html#method-i-hierarchy)** - Returns a tree-like `Hash` structure of all descendants.
|
115
|
+
2. **[`#lineage`](https://shivam091.github.io/core_extensions/Class.html#method-i-lineage)** - Returns an `Array` of all superclasses.
|
116
|
+
3. **[`#leaf_subclasses`](https://shivam091.github.io/core_extensions/Class.html#method-i-leaf_subclasses)** - Returns an `Array` of all descendants which have no subclasses.
|
117
|
+
|
98
118
|
## Contributing
|
99
119
|
|
100
120
|
1. Fork it
|
data/lib/core_extensions/all.rb
CHANGED
@@ -4,7 +4,10 @@
|
|
4
4
|
|
5
5
|
require "core_extensions/array"
|
6
6
|
require "core_extensions/hash"
|
7
|
+
require "core_extensions/true_class"
|
8
|
+
require "core_extensions/false_class"
|
7
9
|
require "core_extensions/nil_class"
|
8
10
|
|
9
|
-
require "core_extensions/
|
11
|
+
require "core_extensions/class"
|
10
12
|
require "core_extensions/module"
|
13
|
+
require "core_extensions/object"
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
require "active_support/core_ext/class/subclasses"
|
6
|
+
|
7
|
+
class Class
|
8
|
+
# Returns a tree-like +Hash+ structure of all descendants.
|
9
|
+
#
|
10
|
+
# ==== Examples
|
11
|
+
#
|
12
|
+
# require 'socket'
|
13
|
+
# IO.hierarchy
|
14
|
+
# #=> {BasicSocket=>{UNIXSocket=>{UNIXServer=>{}}, IPSocket=>{UDPSocket=>{}, TCPSocket=>{TCPServer=>{}}}, Socket=>{}}, File=>{}}
|
15
|
+
def hierarchy
|
16
|
+
subclasses.each_with_object({}) { |k, h| h[k] = k.hierarchy }
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns an +Array+ of all superclasses.
|
20
|
+
#
|
21
|
+
# ==== Examples
|
22
|
+
#
|
23
|
+
# require 'socket'
|
24
|
+
# TCPServer.lineage
|
25
|
+
# #=> [TCPSocket, IPSocket, BasicSocket, IO, Object, BasicObject]
|
26
|
+
def lineage
|
27
|
+
superclass.nil? ? [] : superclass.lineage.unshift(superclass)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns an +Array+ of all descendants which have no subclasses.
|
31
|
+
#
|
32
|
+
# ==== Examples
|
33
|
+
#
|
34
|
+
# require 'socket'
|
35
|
+
# BasicSocket.leaf_subclasses
|
36
|
+
# #=> [Socket, UNIXServer, UDPSocket, TCPServer]
|
37
|
+
def leaf_subclasses
|
38
|
+
descendants.select { |d| d.subclasses.empty? }
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
class FalseClass
|
6
|
+
# Returns +0+ if invoked on +FalseClass+ instance.
|
7
|
+
#
|
8
|
+
# ==== Examples
|
9
|
+
#
|
10
|
+
# false.to_i #=> 0
|
11
|
+
def to_i
|
12
|
+
0
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns +false+ if invoked on +FalseClass+ instance.
|
16
|
+
#
|
17
|
+
# ==== Examples
|
18
|
+
#
|
19
|
+
# false.to_b #=> false
|
20
|
+
def to_b
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
5
|
class NilClass
|
6
|
-
# Returns +true+
|
6
|
+
# Returns +true+ if invoked on `NilClass` instance.
|
7
7
|
#
|
8
8
|
# ==== Examples
|
9
9
|
#
|
@@ -11,4 +11,13 @@ class NilClass
|
|
11
11
|
def blank?
|
12
12
|
true
|
13
13
|
end
|
14
|
+
|
15
|
+
# Returns +false+ if invoked on +NilClass+ instance.
|
16
|
+
#
|
17
|
+
# ==== Examples
|
18
|
+
#
|
19
|
+
# nil.to_b #=> false
|
20
|
+
def to_b
|
21
|
+
false
|
22
|
+
end
|
14
23
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
class TrueClass
|
6
|
+
# Returns +1+ if invoked on +TrueClass+ instance.
|
7
|
+
#
|
8
|
+
# ==== Examples
|
9
|
+
#
|
10
|
+
# true.to_i #=> 1
|
11
|
+
def to_i
|
12
|
+
1
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns +true+ if invoked on +TrueClass+ instance.
|
16
|
+
#
|
17
|
+
# ==== Examples
|
18
|
+
#
|
19
|
+
# true.to_b #=> true
|
20
|
+
def to_b
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rb_core_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harshal LADHE
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -70,6 +70,8 @@ files:
|
|
70
70
|
- lib/core_extensions/array/duplicates.rb
|
71
71
|
- lib/core_extensions/array/inclusion.rb
|
72
72
|
- lib/core_extensions/array/math.rb
|
73
|
+
- lib/core_extensions/class.rb
|
74
|
+
- lib/core_extensions/false_class.rb
|
73
75
|
- lib/core_extensions/hash.rb
|
74
76
|
- lib/core_extensions/hash/access.rb
|
75
77
|
- lib/core_extensions/hash/delete.rb
|
@@ -77,6 +79,7 @@ files:
|
|
77
79
|
- lib/core_extensions/module.rb
|
78
80
|
- lib/core_extensions/nil_class.rb
|
79
81
|
- lib/core_extensions/object.rb
|
82
|
+
- lib/core_extensions/true_class.rb
|
80
83
|
- lib/core_extensions/version.rb
|
81
84
|
- rb_core_extensions.gemspec
|
82
85
|
homepage: https://github.com/shivam091/core_extensions
|