File tree Expand file tree Collapse file tree 4 files changed +47
-2
lines changed Expand file tree Collapse file tree 4 files changed +47
-2
lines changed Original file line number Diff line number Diff line change @@ -24,3 +24,5 @@ Style/FormatString:
24
24
Enabled : false
25
25
Style/DateTime :
26
26
Enabled : false
27
+ Metrics/ClassLength :
28
+ Enabled : false
Original file line number Diff line number Diff line change 175
175
PLATFORMS
176
176
arm64-darwin-21
177
177
arm64-darwin-22
178
+ arm64-darwin-23
178
179
java
179
180
universal-java-11
180
181
universal-java-18
@@ -203,4 +204,4 @@ DEPENDENCIES
203
204
yard
204
205
205
206
BUNDLED WITH
206
- 2.4.19
207
+ 2.5.3
Original file line number Diff line number Diff line change 1
1
require 'date'
2
2
module RubyUnits
3
- # Copyright 2006-2023
3
+ # Copyright 2006-2024
4
4
# @author Kevin C. Olbrich, Ph.D.
5
5
# @see https://github.com/olbrich/ruby-units
6
6
#
@@ -165,6 +165,17 @@ class << self
165
165
166
166
# Class Methods
167
167
168
+ # Callback triggered when a subclass is created. This properly sets up the internal variables, and copies
169
+ # definitions from the parent class.
170
+ #
171
+ # @param [Class] subclass
172
+ def self . inherited ( subclass )
173
+ super
174
+ subclass . definitions = definitions . dup
175
+ subclass . instance_variable_set ( :@kinds , @kinds . dup )
176
+ subclass . setup
177
+ end
178
+
168
179
# setup internal arrays and hashes
169
180
# @return [Boolean]
170
181
def self . setup
Original file line number Diff line number Diff line change
1
+ RSpec . describe 'Subclass' do
2
+ subject ( :subclass ) { Class . new ( RubyUnits ::Unit ) }
3
+
4
+ it 'can be subclassed' do
5
+ expect ( subclass ) . to be < RubyUnits ::Unit
6
+ end
7
+
8
+ it 'can be instantiated' do
9
+ expect ( subclass . new ( '1 m' ) ) . to be_a ( RubyUnits ::Unit )
10
+ end
11
+
12
+ it 'compares to the parent class' do
13
+ expect ( subclass . new ( '1 m' ) ) . to eq ( RubyUnits ::Unit . new ( '1 m' ) )
14
+ end
15
+
16
+ it 'can be added to another subclass instance' do
17
+ expect ( subclass . new ( '1 m' ) + subclass . new ( '1 m' ) ) . to eq ( RubyUnits ::Unit . new ( '2 m' ) )
18
+ end
19
+
20
+ it 'returns a subclass object when added to another instance of a subclass' do
21
+ expect ( subclass . new ( '1 m' ) + subclass . new ( '1 m' ) ) . to be_an_instance_of ( subclass )
22
+ end
23
+
24
+ it 'returns an instance of the parent class when added to another instance of a subclass' do
25
+ expect ( RubyUnits ::Unit . new ( '1 m' ) + subclass . new ( '1 m' ) ) . to be_an_instance_of ( RubyUnits ::Unit )
26
+ end
27
+
28
+ it 'returns an instance of the subclass when added to an instance of the parent class' do
29
+ expect ( subclass . new ( '1 m' ) + RubyUnits ::Unit . new ( '1 m' ) ) . to be_an_instance_of ( subclass )
30
+ end
31
+ end
You can’t perform that action at this time.
0 commit comments