vector_number 0.4.2 → 0.4.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/README.md +1 -1
- data/lib/vector_number/enumerating.rb +4 -4
- data/lib/vector_number/math_converting.rb +2 -2
- data/lib/vector_number/numeric_refinements.rb +15 -3
- data/lib/vector_number/stringifying.rb +1 -1
- data/lib/vector_number/version.rb +1 -1
- data/lib/vector_number.rb +5 -5
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05d6547284c73b585a149026d1a0a123f5914e13c81856e2419180f44f05404c
|
4
|
+
data.tar.gz: 2b942db9aa53c4e8027540a630355f2defd64de96d3c90bbd55e539844f32bfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8d079e1d0915ae151ac2dcb28621f672365e55efa0cb505ad3e846eb3619eababa4e39e5654098bb305fafa2ff602a1085c913c5d6fc8ea02922688087fb09b
|
7
|
+
data.tar.gz: f09e3d71187e9c202ff1a4960cbf19b7a02f679dc6b49b7b1e96e42e074a66990507262ab1648182217b8dacc980fe0ed777c48ac76db44734dccfdf34a7b488
|
data/README.md
CHANGED
@@ -95,7 +95,7 @@ VectorNumber[:s] / VectorNumber[3] # => (1/3⋅s)
|
|
95
95
|
### (Somewhat) advanced usage
|
96
96
|
|
97
97
|
> [!TIP]
|
98
|
-
> Look at
|
98
|
+
> Look at API documentation for all methods.
|
99
99
|
|
100
100
|
#### Frozenness
|
101
101
|
VectorNumbers are always frozen, as a number should be. However, they hold references to units (keys), which aren't frozen or duplicated. It is the user's responsibility to ensure that keys aren't mutated, the same as it is for Hash.
|
@@ -36,10 +36,10 @@ class VectorNumber
|
|
36
36
|
# @see Enumerator
|
37
37
|
#
|
38
38
|
# @since 0.1.0
|
39
|
-
def each(&)
|
39
|
+
def each(&block)
|
40
40
|
return to_enum { size } unless block_given?
|
41
41
|
|
42
|
-
@data.each(&)
|
42
|
+
@data.each(&block)
|
43
43
|
self
|
44
44
|
end
|
45
45
|
|
@@ -85,10 +85,10 @@ class VectorNumber
|
|
85
85
|
# @return [Hash{Object => Integer, Float, Rational, BigDecimal}]
|
86
86
|
#
|
87
87
|
# @since 0.1.0
|
88
|
-
def to_h(&)
|
88
|
+
def to_h(&block)
|
89
89
|
# TODO: Remove block argument.
|
90
90
|
if block_given?
|
91
|
-
@data.to_h(&)
|
91
|
+
@data.to_h(&block)
|
92
92
|
else
|
93
93
|
@data.dup
|
94
94
|
end
|
@@ -110,10 +110,10 @@ class VectorNumber
|
|
110
110
|
when :even then :half_even
|
111
111
|
else :half_up
|
112
112
|
end
|
113
|
-
new { _1.is_a?(BigDecimal) ? _1.round(digits, bd_mode) : _1.round(digits, half:) }
|
113
|
+
new { _1.is_a?(BigDecimal) ? _1.round(digits, bd_mode) : _1.round(digits, half: half) }
|
114
114
|
# :nocov:
|
115
115
|
else
|
116
|
-
new { _1.round(digits, half:) }
|
116
|
+
new { _1.round(digits, half: half) }
|
117
117
|
end
|
118
118
|
# :nocov:
|
119
119
|
end
|
@@ -8,6 +8,8 @@ class VectorNumber
|
|
8
8
|
# - refinement for +Complex#<=>+ to work with classes implementing +<=>+;
|
9
9
|
# - refinement for +Kernel#BigDecimal+ to work with classes implementing +to_d+.
|
10
10
|
#
|
11
|
+
# @note Refinements won't work on Ruby 3.0.
|
12
|
+
#
|
11
13
|
# @example activating refinements
|
12
14
|
# require "vector_number/numeric_refinements"
|
13
15
|
# using VectorNumber::NumericRefinements
|
@@ -41,7 +43,11 @@ class VectorNumber
|
|
41
43
|
end
|
42
44
|
|
43
45
|
if (Complex(1, 0) <=> VectorNumber[1]).nil?
|
44
|
-
refine(Complex)
|
46
|
+
refine(Complex) do
|
47
|
+
import_methods CommutativeShuttle
|
48
|
+
rescue
|
49
|
+
warn "Numeric refinements are not available on Ruby < 3.1"
|
50
|
+
end
|
45
51
|
end
|
46
52
|
|
47
53
|
# Refinement module to change Kernel#BigDecimal so it works with +#to_d+.
|
@@ -68,11 +74,17 @@ class VectorNumber
|
|
68
74
|
if value.respond_to?(:to_d)
|
69
75
|
ndigits.nil? ? value.to_d : value.to_d(ndigits)
|
70
76
|
else
|
71
|
-
ndigits.nil? ? super(value, exception:) : super
|
77
|
+
ndigits.nil? ? super(value, exception: exception) : super
|
72
78
|
end
|
73
79
|
end
|
74
80
|
end
|
75
81
|
|
76
|
-
|
82
|
+
if defined?(BigDecimal)
|
83
|
+
refine(Kernel) do
|
84
|
+
import_methods BigDecimalToD
|
85
|
+
rescue
|
86
|
+
warn "Numeric refinements are not available on Ruby < 3.1"
|
87
|
+
end
|
88
|
+
end
|
77
89
|
end
|
78
90
|
end
|
data/lib/vector_number.rb
CHANGED
@@ -107,12 +107,12 @@ class VectorNumber
|
|
107
107
|
# @yieldparam coefficient [Integer, Float, Rational, BigDecimal]
|
108
108
|
# @yieldreturn [Integer, Float, Rational, BigDecimal] new coefficient
|
109
109
|
# @raise [RangeError] if any pesky non-reals get where they shouldn't
|
110
|
-
def initialize(values = nil, options = nil, &)
|
110
|
+
def initialize(values = nil, options = nil, &transform)
|
111
111
|
# @type var options: Hash[Symbol, Object]
|
112
112
|
initialize_from(values)
|
113
|
-
apply_transform(&)
|
113
|
+
apply_transform(&transform)
|
114
114
|
finalize_contents
|
115
|
-
save_options(options, values:)
|
115
|
+
save_options(options, values: values)
|
116
116
|
@options.freeze
|
117
117
|
@data.freeze
|
118
118
|
freeze
|
@@ -152,8 +152,8 @@ class VectorNumber
|
|
152
152
|
# @yieldparam coefficient [Integer, Float, Rational, BigDecimal]
|
153
153
|
# @yieldreturn [Integer, Float, Rational, BigDecimal] new coefficient
|
154
154
|
# @return [VectorNumber]
|
155
|
-
def new(from = self, &)
|
156
|
-
self.class.new(from, options, &)
|
155
|
+
def new(from = self, &transform)
|
156
|
+
self.class.new(from, options, &transform)
|
157
157
|
end
|
158
158
|
|
159
159
|
# Check if +other+ is a real number.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vector_number
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandr Bulancov
|
@@ -42,9 +42,9 @@ licenses:
|
|
42
42
|
metadata:
|
43
43
|
homepage_uri: https://github.com/trinistr/vector_number
|
44
44
|
bug_tracker_uri: https://github.com/trinistr/vector_number/issues
|
45
|
-
documentation_uri: https://rubydoc.info/gems/vector_number/0.4.
|
46
|
-
source_code_uri: https://github.com/trinistr/vector_number/tree/v0.4.
|
47
|
-
changelog_uri: https://github.com/trinistr/vector_number/blob/v0.4.
|
45
|
+
documentation_uri: https://rubydoc.info/gems/vector_number/0.4.3
|
46
|
+
source_code_uri: https://github.com/trinistr/vector_number/tree/v0.4.3
|
47
|
+
changelog_uri: https://github.com/trinistr/vector_number/blob/v0.4.3/CHANGELOG.md
|
48
48
|
rubygems_mfa_required: 'true'
|
49
49
|
rdoc_options:
|
50
50
|
- "--main"
|
@@ -55,7 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
55
|
requirements:
|
56
56
|
- - ">="
|
57
57
|
- !ruby/object:Gem::Version
|
58
|
-
version: 3.
|
58
|
+
version: 3.0.0
|
59
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
61
|
- - ">="
|