ruby-units 2.4.1 → 3.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cef2eee9d07cdfbb9761babe05cf20dcd2d64fcd8b1c72e1c82f0c7120f0aafe
4
- data.tar.gz: 3b7f5ecd1dff12af14de4f9c6eb5109a7a09f0fa3223f5880befbb99a556237b
3
+ metadata.gz: 9e423976ff1953c233f4085f282b9431d9dc8f7fa840403221eb42d363384809
4
+ data.tar.gz: 22c656c48317d6af891eb3e3e1fbfcecc48fd113a9fff76004c829417b4ed305
5
5
  SHA512:
6
- metadata.gz: 44f63528e99535c8d5dd56ce7a2ca4f2a1fe800ace101495be272c5fa9e6c25b6abd3d1f35c695cf69ec848b333c8b9147f044e275122124bf08b1acee432bcb
7
- data.tar.gz: cb72ea094586f7750524527c605f151431b0c96d3d3350337eceed2f7fb29d30568f14f0c2f9ee2179b0f8ca638b1cfef580c8929c2551ff9085107bd6d7cd8f
6
+ metadata.gz: '096f48bed8904c0e450151e1df844493826b665ffaad305b08c3315c215e97b82643ee450b8e6208930aa936128b835d62a661bc9823302442311da16a02bca9'
7
+ data.tar.gz: 51814f9dc8b31fea8a4bb789a8f7e474a453737d4e9f6eba7ed2548285d99d21608ec14111ec024017abc04e57ea50556be1b597f6cb3688d4d7cd0ba665dfcc
@@ -42,7 +42,7 @@ jobs:
42
42
 
43
43
  # Initializes the CodeQL tools for scanning.
44
44
  - name: Initialize CodeQL
45
- uses: github/codeql-action/init@v1
45
+ uses: github/codeql-action/init@v2
46
46
  with:
47
47
  languages: ${{ matrix.language }}
48
48
  # If you wish to specify custom queries, you can do so here or in a config file.
@@ -53,7 +53,7 @@ jobs:
53
53
  # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
54
54
  # If this step fails, then you should remove it and run the build manually (see below)
55
55
  - name: Autobuild
56
- uses: github/codeql-action/autobuild@v1
56
+ uses: github/codeql-action/autobuild@v2
57
57
 
58
58
  # ℹ️ Command-line programs to run using the OS shell.
59
59
  # 📚 https://git.io/JvXDl
@@ -67,4 +67,4 @@ jobs:
67
67
  # make release
68
68
 
69
69
  - name: Perform CodeQL Analysis
70
- uses: github/codeql-action/analyze@v1
70
+ uses: github/codeql-action/analyze@v2
data/.solargraph.yml CHANGED
@@ -9,8 +9,8 @@ exclude:
9
9
  require: []
10
10
  domains: []
11
11
  reporters:
12
- - rubocop
13
12
  - require_not_found
13
+ - typecheck
14
14
  require_paths: []
15
15
  plugins: []
16
16
  max_files: 5000
data/.tool-versions ADDED
@@ -0,0 +1,3 @@
1
+ # ruby jruby-9.3.8.0
2
+ # uncomment this to use jruby
3
+ java adoptopenjdk-18.0.1+10
data/CHANGELOG.txt CHANGED
@@ -1,6 +1,8 @@
1
1
  Change Log for Ruby-units
2
2
  =========================
3
- see Github releases (https://github.com/olbrich/ruby-units/releases)
3
+
4
+ see GitHub releases (https://github.com/olbrich/ruby-units/releases) for more recent releases. This file will no longer
5
+ be updated.
4
6
 
5
7
  2020-12-29 2.3.2 * Remove Jeweler (see #178) also adds Code of Conduct
6
8
  * Fix specs related to Complex comparisons (see #213)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-units (2.4.1)
4
+ ruby-units (3.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -75,11 +75,11 @@ GEM
75
75
  racc (1.6.0-java)
76
76
  rainbow (3.1.1)
77
77
  rake (13.0.6)
78
- rb-fsevent (0.11.1)
78
+ rb-fsevent (0.11.2)
79
79
  rb-inotify (0.10.1)
80
80
  ffi (~> 1.0)
81
81
  redcarpet (3.5.1)
82
- regexp_parser (2.5.0)
82
+ regexp_parser (2.6.0)
83
83
  reline (0.3.1)
84
84
  io-console (~> 0.5)
85
85
  reverse_markdown (2.1.1)
@@ -91,14 +91,14 @@ GEM
91
91
  rspec-mocks (~> 3.11.0)
92
92
  rspec-core (3.11.0)
93
93
  rspec-support (~> 3.11.0)
94
- rspec-expectations (3.11.0)
94
+ rspec-expectations (3.11.1)
95
95
  diff-lcs (>= 1.2.0, < 2.0)
96
96
  rspec-support (~> 3.11.0)
97
97
  rspec-mocks (3.11.1)
98
98
  diff-lcs (>= 1.2.0, < 2.0)
99
99
  rspec-support (~> 3.11.0)
100
- rspec-support (3.11.0)
101
- rubocop (1.35.1)
100
+ rspec-support (3.11.1)
101
+ rubocop (1.36.0)
102
102
  json (~> 2.3)
103
103
  parallel (~> 1.10)
104
104
  parser (>= 3.1.2.1)
@@ -112,8 +112,8 @@ GEM
112
112
  parser (>= 3.1.1.0)
113
113
  rubocop-rake (0.6.0)
114
114
  rubocop (~> 1.0)
115
- rubocop-rspec (2.12.1)
116
- rubocop (~> 1.31)
115
+ rubocop-rspec (2.13.2)
116
+ rubocop (~> 1.33)
117
117
  ruby-maven (3.3.13)
118
118
  ruby-maven-libs (~> 3.3.9)
119
119
  ruby-maven-libs (3.3.9)
@@ -126,7 +126,7 @@ GEM
126
126
  simplecov_json_formatter (~> 0.1)
127
127
  simplecov-html (0.12.3)
128
128
  simplecov_json_formatter (0.1.4)
129
- solargraph (0.46.0)
129
+ solargraph (0.47.2)
130
130
  backport (~> 1.2)
131
131
  benchmark
132
132
  bundler (>= 1.17.2)
@@ -147,7 +147,7 @@ GEM
147
147
  terminal-notifier-guard (1.7.0)
148
148
  thor (1.2.1)
149
149
  tilt (2.0.11)
150
- unicode-display_width (2.2.0)
150
+ unicode-display_width (2.3.0)
151
151
  webrick (1.7.0)
152
152
  yard (0.9.28)
153
153
  webrick (~> 1.7.0)
@@ -156,6 +156,7 @@ PLATFORMS
156
156
  java
157
157
  ruby
158
158
  universal-java-11
159
+ universal-java-18
159
160
  x86_64-darwin-19
160
161
 
161
162
  DEPENDENCIES
@@ -1,9 +1,19 @@
1
- class Array
2
- # Construct a unit from an array
3
- # @example [1, 'mm'].to_unit => RubyUnits::Unit.new("1 mm")
4
- # @return (see RubyUnits::Unit#initialize)
5
- # @param [Object] other convert to same units as passed
6
- def to_unit(other = nil)
7
- other ? RubyUnits::Unit.new(self).convert_to(other) : RubyUnits::Unit.new(self)
1
+ module RubyUnits
2
+ # Extra methods for [::Array] to support conversion to [RubyUnits::Unit]
3
+ module Array
4
+ # Construct a unit from an array
5
+ #
6
+ # @example [1, 'mm'].to_unit => RubyUnits::Unit.new("1 mm")
7
+ # @param [RubyUnits::Unit, String] other convert to same units as passed
8
+ # @return [RubyUnits::Unit]
9
+ def to_unit(other = nil)
10
+ other ? RubyUnits::Unit.new(self).convert_to(other) : RubyUnits::Unit.new(self)
11
+ end
8
12
  end
9
13
  end
14
+
15
+ # @note Do this instead of Array.prepend(RubyUnits::Array) to avoid YARD warnings
16
+ # @see https://github.com/lsegal/yard/issues/1353
17
+ class Array
18
+ prepend(RubyUnits::Array)
19
+ end
@@ -1,21 +1,34 @@
1
1
  module RubyUnits
2
- class Unit < Numeric
3
- @@cached_units = {}
2
+ # Performance optimizations to avoid creating units unnecessarily
3
+ class Cache
4
+ attr_accessor :data
4
5
 
5
- class Cache
6
- def self.get(key = nil)
7
- key.nil? ? @@cached_units : @@cached_units[key]
8
- end
6
+ def initialize
7
+ clear
8
+ end
9
+
10
+ # @param key [String, #to_unit]
11
+ # @return [RubyUnits::Unit, nil]
12
+ def get(key)
13
+ key = key&.to_unit&.units unless key.is_a?(String)
14
+ data[key]
15
+ end
9
16
 
10
- def self.set(key, value)
11
- @@cached_units[key] = value
12
- end
17
+ # @param key [String, #to_unit]
18
+ # @return [void]
19
+ def set(key, value)
20
+ key = key.to_unit.units unless key.is_a?(String)
21
+ data[key] = value
22
+ end
23
+
24
+ # @return [Array<String>]
25
+ def keys
26
+ data.keys
27
+ end
13
28
 
14
- def self.clear
15
- @@cached_units = {}
16
- @@base_unit_cache = {}
17
- Unit.new(1)
18
- end
29
+ # Reset the cache
30
+ def clear
31
+ @data = {}
19
32
  end
20
33
  end
21
34
  end
@@ -1,10 +1,3 @@
1
- # allow for optional configuration of RubyUnits
2
- #
3
- # Usage:
4
- #
5
- # RubyUnits.configure do |config|
6
- # config.separator = false
7
- # end
8
1
  module RubyUnits
9
2
  class << self
10
3
  attr_writer :configuration
@@ -18,6 +11,13 @@ module RubyUnits
18
11
  @configuration = Configuration.new
19
12
  end
20
13
 
14
+ # allow for optional configuration of RubyUnits
15
+ #
16
+ # Usage:
17
+ #
18
+ # RubyUnits.configure do |config|
19
+ # config.separator = false
20
+ # end
21
21
  def self.configure
22
22
  yield configuration
23
23
  end
@@ -34,7 +34,7 @@ module RubyUnits
34
34
  end
35
35
 
36
36
  def separator=(value)
37
- raise ArgumentError, "configuration 'separator' may only be true or false" unless value == true || value == false
37
+ raise ArgumentError, "configuration 'separator' may only be true or false" unless [true, false].include?(value)
38
38
 
39
39
  @separator = value ? ' ' : nil
40
40
  end
@@ -1,64 +1,57 @@
1
1
  require 'date'
2
2
 
3
- # Allow date objects to do offsets by a time unit
4
- # Date.today + Unit.new("1 week") => gives today+1 week
5
- class Date
6
- alias unit_date_add +
7
- # @param [Object] other
8
- # @return [Unit]
9
- def +(other)
10
- case other
11
- when RubyUnits::Unit
12
- other = other.convert_to('d').round if %w[y decade century].include? other.units
13
- unit_date_add(other.convert_to('day').scalar)
14
- else
15
- unit_date_add(other)
3
+ module RubyUnits
4
+ # Extra methods for [::Date] to allow it to be used as a [RubyUnits::Unit]
5
+ module Date
6
+ # Allow date objects to do offsets by a time unit
7
+ #
8
+ # @example Date.today + Unit.new("1 week") => gives today+1 week
9
+ # @param [RubyUnits::Unit, Object] other
10
+ # @return [RubyUnits::Unit]
11
+ def +(other)
12
+ case other
13
+ when RubyUnits::Unit
14
+ other = other.convert_to('d').round if %w[y decade century].include? other.units
15
+ super(other.convert_to('day').scalar)
16
+ else
17
+ super
18
+ end
16
19
  end
17
- end
18
20
 
19
- alias unit_date_sub -
20
- # @param [Object] other
21
- # @return [Unit]
22
- def -(other)
23
- case other
24
- when RubyUnits::Unit
25
- other = other.convert_to('d').round if %w[y decade century].include? other.units
26
- unit_date_sub(other.convert_to('day').scalar)
27
- else
28
- unit_date_sub(other)
21
+ # Allow date objects to do offsets by a time unit
22
+ #
23
+ # @example Date.today - Unit.new("1 week") => gives today-1 week
24
+ # @param [RubyUnits::Unit, Object] other
25
+ # @return [RubyUnits::Unit]
26
+ def -(other)
27
+ case other
28
+ when RubyUnits::Unit
29
+ other = other.convert_to('d').round if %w[y decade century].include? other.units
30
+ super(other.convert_to('day').scalar)
31
+ else
32
+ super
33
+ end
29
34
  end
30
- end
31
35
 
32
- # Construct a unit from a Date
33
- # @example Date.today.to_unit => Unit
34
- # @return (see Unit#initialize)
35
- # @param [Object] other convert to same units as passed
36
- def to_unit(other = nil)
37
- other ? RubyUnits::Unit.new(self).convert_to(other) : RubyUnits::Unit.new(self)
38
- end
39
-
40
- # :nocov_19:
41
- unless Date.instance_methods.include?(:to_time)
42
- # @return [Time]
43
- def to_time
44
- Time.local(*ParseDate.parsedate(to_s))
36
+ # Construct a unit from a Date. This returns the number of days since the
37
+ # start of the Julian calendar as a Unit.
38
+ #
39
+ # @example Date.today.to_unit => Unit
40
+ # @return [RubyUnits::Unit]
41
+ # @param other [RubyUnits::Unit, String] convert to same units as passed
42
+ def to_unit(other = nil)
43
+ other ? RubyUnits::Unit.new(self).convert_to(other) : RubyUnits::Unit.new(self)
45
44
  end
46
- end
47
- # :nocov_19:
48
45
 
49
- alias units_datetime_inspect inspect
50
- # @deprecated
51
- def inspect(dump = false)
52
- return units_datetime_inspect if dump
53
- to_s
54
- end
55
-
56
- unless Date.instance_methods.include?(:to_date)
57
- # :nocov_19:
58
- # @return [Date]
59
- def to_date
60
- Date.civil(year, month, day)
46
+ # @deprecated
47
+ def inspect(dump = false)
48
+ dump ? super : to_s
61
49
  end
62
- # :nocov_19:
63
50
  end
64
51
  end
52
+
53
+ # @note Do this instead of Date.prepend(RubyUnits::Date) to avoid YARD warnings
54
+ # @see https://github.com/lsegal/yard/issues/1353
55
+ class Date
56
+ prepend RubyUnits::Date
57
+ end
@@ -1,125 +1,148 @@
1
- # Math will convert unit objects to radians and then attempt to use the value for
2
- # trigonometric functions.
3
- module Math
4
- alias unit_sqrt sqrt
5
- # @return [Numeric]
6
- def sqrt(n)
7
- if n.is_a?(RubyUnits::Unit)
8
- (n**Rational(1, 2)).to_unit
9
- else
10
- unit_sqrt(n)
1
+ module RubyUnits
2
+ # Math will convert unit objects to radians and then attempt to use the value for
3
+ # trigonometric functions.
4
+ module Math
5
+ # Take the square root of a unit or number
6
+ #
7
+ # @param number [Numeric, RubyUnits::Unit]
8
+ # @return [Numeric, RubyUnits::Unit]
9
+ def sqrt(number)
10
+ if number.is_a?(RubyUnits::Unit)
11
+ (number**Rational(1, 2)).to_unit
12
+ else
13
+ super
14
+ end
11
15
  end
12
- end
13
- # @return [Numeric]
14
- module_function :unit_sqrt
15
- # @return [Numeric]
16
- module_function :sqrt
17
-
18
- #:nocov:
19
- if respond_to?(:cbrt)
20
- alias unit_cbrt cbrt
16
+
17
+ # Take the cube root of a unit or number
18
+ #
19
+ # @param number [Numeric, RubyUnits::Unit]
20
+ # @return [Numeric, RubyUnits::Unit]
21
+ def cbrt(number)
22
+ if number.is_a?(RubyUnits::Unit)
23
+ (number**Rational(1, 3)).to_unit
24
+ else
25
+ super
26
+ end
27
+ end
28
+
29
+ # @param angle [Numeric, RubyUnits::Unit]
21
30
  # @return [Numeric]
22
- def cbrt(n)
23
- if RubyUnits::Unit === n
24
- (n**Rational(1, 3)).to_unit
31
+ def sin(angle)
32
+ angle.is_a?(RubyUnits::Unit) ? super(angle.convert_to('radian').scalar) : super
33
+ end
34
+
35
+ # @param number [Numeric, RubyUnits::Unit]
36
+ # @return [Numeric, RubyUnits::Unit]
37
+ def asin(number)
38
+ if number.is_a?(RubyUnits::Unit)
39
+ [super(number), 'radian'].to_unit
25
40
  else
26
- unit_cbrt(n)
41
+ super
27
42
  end
28
43
  end
44
+
45
+ # @param angle [Numeric, RubyUnits::Unit]
29
46
  # @return [Numeric]
30
- module_function :unit_cbrt
47
+ def cos(angle)
48
+ angle.is_a?(RubyUnits::Unit) ? super(angle.convert_to('radian').scalar) : super
49
+ end
50
+
51
+ # @param number [Numeric, RubyUnits::Unit]
52
+ # @return [Numeric, RubyUnits::Unit]
53
+ def acos(number)
54
+ if number.is_a?(RubyUnits::Unit)
55
+ [super(number), 'radian'].to_unit
56
+ else
57
+ super
58
+ end
59
+ end
60
+
61
+ # @param number [Numeric, RubyUnits::Unit]
31
62
  # @return [Numeric]
32
- module_function :cbrt
33
- end
34
- #:nocov:
63
+ def sinh(number)
64
+ number.is_a?(RubyUnits::Unit) ? super(number.convert_to('radian').scalar) : super
65
+ end
35
66
 
36
- alias unit_sin sin
37
- # @return [Numeric]
38
- def sin(n)
39
- RubyUnits::Unit === n ? unit_sin(n.convert_to('radian').scalar) : unit_sin(n)
40
- end
41
- # @return [Numeric]
42
- module_function :unit_sin
43
- # @return [Numeric]
44
- module_function :sin
45
-
46
- alias unit_cos cos
47
- # @return [Numeric]
48
- def cos(n)
49
- RubyUnits::Unit === n ? unit_cos(n.convert_to('radian').scalar) : unit_cos(n)
50
- end
51
- # @return [Numeric]
52
- module_function :unit_cos
53
- # @return [Numeric]
54
- module_function :cos
55
-
56
- alias unit_sinh sinh
57
- # @return [Numeric]
58
- def sinh(n)
59
- RubyUnits::Unit === n ? unit_sinh(n.convert_to('radian').scalar) : unit_sinh(n)
60
- end
61
- # @return [Numeric]
62
- module_function :unit_sinh
63
- # @return [Numeric]
64
- module_function :sinh
65
-
66
- alias unit_cosh cosh
67
- # @return [Numeric]
68
- def cosh(n)
69
- RubyUnits::Unit === n ? unit_cosh(n.convert_to('radian').scalar) : unit_cosh(n)
70
- end
71
- # @return [Numeric]
72
- module_function :unit_cosh
73
- # @return [Numeric]
74
- module_function :cosh
75
-
76
- alias unit_tan tan
77
- # @return [Numeric]
78
- def tan(n)
79
- RubyUnits::Unit === n ? unit_tan(n.convert_to('radian').scalar) : unit_tan(n)
80
- end
81
- # @return [Numeric]
82
- module_function :tan
83
- # @return [Numeric]
84
- module_function :unit_tan
85
-
86
- alias unit_tanh tanh
87
- # @return [Numeric]
88
- def tanh(n)
89
- RubyUnits::Unit === n ? unit_tanh(n.convert_to('radian').scalar) : unit_tanh(n)
90
- end
91
- # @return [Numeric]
92
- module_function :unit_tanh
93
- # @return [Numeric]
94
- module_function :tanh
95
-
96
- alias unit_hypot hypot
97
- # Convert parameters to consistent units and perform the function
98
- # @return [Numeric]
99
- def hypot(x, y)
100
- if RubyUnits::Unit === x && RubyUnits::Unit === y
101
- (x**2 + y**2)**Rational(1, 2)
102
- else
103
- unit_hypot(x, y)
67
+ # @param number [Numeric, RubyUnits::Unit]
68
+ # @return [Numeric]
69
+ def cosh(number)
70
+ number.is_a?(RubyUnits::Unit) ? super(number.convert_to('radian').scalar) : super
104
71
  end
105
- end
106
- # @return [Numeric]
107
- module_function :unit_hypot
108
- # @return [Numeric]
109
- module_function :hypot
110
-
111
- alias unit_atan2 atan2
112
- # @return [Numeric]
113
- def atan2(x, y)
114
- raise ArgumentError, 'Incompatible RubyUnits::Units' if (x.is_a?(RubyUnits::Unit) && y.is_a?(RubyUnits::Unit)) && !x.compatible?(y)
115
- if (x.is_a?(RubyUnits::Unit) && y.is_a?(RubyUnits::Unit)) && x.compatible?(y)
116
- Math.unit_atan2(x.base_scalar, y.base_scalar)
117
- else
118
- Math.unit_atan2(x, y)
72
+
73
+ # @param angle [Numeric, RubyUnits::Unit]
74
+ # @return [Numeric]
75
+ def tan(angle)
76
+ angle.is_a?(RubyUnits::Unit) ? super(angle.convert_to('radian').scalar) : super
77
+ end
78
+
79
+ # @param number [Numeric, RubyUnits::Unit]
80
+ # @return [Numeric]
81
+ def tanh(number)
82
+ number.is_a?(RubyUnits::Unit) ? super(number.convert_to('radian').scalar) : super
83
+ end
84
+
85
+ # @param x [Numeric, RubyUnits::Unit]
86
+ # @param y [Numeric, RubyUnits::Unit]
87
+ # @return [Numeric]
88
+ def hypot(x, y)
89
+ if x.is_a?(RubyUnits::Unit) && y.is_a?(RubyUnits::Unit)
90
+ ((x**2) + (y**2))**Rational(1, 2)
91
+ else
92
+ super
93
+ end
94
+ end
95
+
96
+ # @param number [Numeric, RubyUnits::Unit]
97
+ # @return [Numeric] if argument is a number
98
+ # @return [RubyUnits::Unit] if argument is a unit
99
+ def atan(number)
100
+ if number.is_a?(RubyUnits::Unit)
101
+ [super(number), 'radian'].to_unit
102
+ else
103
+ super
104
+ end
105
+ end
106
+
107
+ # @param x [Numeric, RubyUnits::Unit]
108
+ # @param y [Numeric, RubyUnits::Unit]
109
+ # @return [Numeric] if all parameters are numbers
110
+ # @return [RubyUnits::Unit] if parameters are units
111
+ # @raise [ArgumentError] if parameters are not numbers or compatible units
112
+ def atan2(x, y)
113
+ raise ArgumentError, 'Incompatible RubyUnits::Units' if (x.is_a?(RubyUnits::Unit) && y.is_a?(RubyUnits::Unit)) && !x.compatible?(y)
114
+
115
+ if (x.is_a?(RubyUnits::Unit) && y.is_a?(RubyUnits::Unit)) && x.compatible?(y)
116
+ [super(x.base_scalar, y.base_scalar), 'radian'].to_unit
117
+ else
118
+ super
119
+ end
120
+ end
121
+
122
+ # @param number [Numeric, RubyUnits::Unit]
123
+ # @return [Numeric]
124
+ def log10(number)
125
+ if number.is_a?(RubyUnits::Unit)
126
+ super(number.to_f)
127
+ else
128
+ super
129
+ end
130
+ end
131
+
132
+ # @param number [Numeric, RubyUnits::Unit]
133
+ # @param base [Numeric]
134
+ # @return [Numeric]
135
+ def log(number, base = ::Math::E)
136
+ if number.is_a?(RubyUnits::Unit)
137
+ super(number.to_f, base)
138
+ else
139
+ super
140
+ end
119
141
  end
120
142
  end
121
- # @return [Numeric]
122
- module_function :unit_atan2
123
- # @return [Numeric]
124
- module_function :atan2
143
+ end
144
+
145
+ # @see https://github.com/lsegal/yard/issues/1353
146
+ module Math
147
+ singleton_class.prepend(RubyUnits::Math)
125
148
  end
@@ -1,7 +1,23 @@
1
- class Numeric
2
- # make a unitless unit with a given scalar
3
- # @return (see RubyUnits::Unit#initialize)
4
- def to_unit(other = nil)
5
- other ? RubyUnits::Unit.new(self, other) : RubyUnits::Unit.new(self)
1
+ module RubyUnits
2
+ # Extra methods for [::Numeric] to allow it to be used as a [RubyUnits::Unit]
3
+ module Numeric
4
+ # Make a unitless unit with a given scalar.
5
+ # > In ruby-units <= 2.3.2 this method would create a new [RubyUnits::Unit]
6
+ # > with the scalar and passed in units. This was changed to be more
7
+ # > consistent with the behavior of [#to_unit]. Specifically the argument is
8
+ # > used as a convenience method to convert the unitless scalar unit to a
9
+ # > compatible unitless unit.
10
+ #
11
+ # @param other [RubyUnits::Unit, String] convert to same units as passed
12
+ # @return [RubyUnits::Unit]
13
+ def to_unit(other = nil)
14
+ other ? RubyUnits::Unit.new(self).convert_to(other) : RubyUnits::Unit.new(self)
15
+ end
6
16
  end
7
17
  end
18
+
19
+ # @note Do this instead of Numeric.prepend(RubyUnits::Numeric) to avoid YARD warnings
20
+ # @see https://github.com/lsegal/yard/issues/1353
21
+ class Numeric
22
+ prepend(RubyUnits::Numeric)
23
+ end