Skip to content

Commit ff98165

Browse files
committed
Update for Ruby 2.7 compatibility
1 parent 539a156 commit ff98165

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ rvm:
55
- "2.4.0"
66
- "2.5.0"
77
- "2.6.0"
8+
- ruby-head
89
- jruby-9.2.5.0
910
matrix:
1011
allow_failures:

lib/time_calc.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,9 @@ def ==(other)
274274
OPERATIONS = MATH_OPERATIONS.+(%i[to step for]).freeze
275275

276276
OPERATIONS.each do |name|
277-
define_method(name) { |*args, &block|
278-
@value.public_send(name, *args, &block).then { |res| res.is_a?(Value) ? res.unwrap : res }
277+
define_method(name) { |*args, **kwargs, &block|
278+
@value.public_send(name, *args, **kwargs, &block)
279+
.then { |res| res.is_a?(Value) ? res.unwrap : res }
279280
}
280281
end
281282

lib/time_calc/diff.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def coerce_zones(from, to)
285285
# Will coerce Date to Time or DateTime, with the _zone of the latter_
286286
def coerce_date(date, other)
287287
TimeCalc.(other)
288-
.merge(Units::DEFAULTS.merge(year: date.year, month: date.month, day: date.day))
288+
.merge(**Units::DEFAULTS.merge(year: date.year, month: date.month, day: date.day))
289289
end
290290
end
291291
end

lib/time_calc/value.rb

+17-15
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@
77
require 'backports/2.5.0/hash/slice'
88
require 'backports/2.5.0/enumerable/all'
99

10-
# @private
11-
# TODO: It is included in Ruby 2.7. Replace with backports when it will be there.
12-
class Enumerator
13-
NOVALUE = Object.new.freeze
14-
15-
def self.produce(initial = NOVALUE)
16-
fail ArgumentError, 'No block given' unless block_given?
17-
18-
Enumerator.new do |y|
19-
val = initial == NOVALUE ? yield() : initial
20-
21-
loop do
22-
y << val
23-
val = yield(val)
10+
if RUBY_VERSION < '2.7'
11+
# @private
12+
# TODO: Replace with backports after 2.7 release
13+
class Enumerator
14+
NOVALUE = Object.new.freeze
15+
16+
def self.produce(initial = NOVALUE)
17+
fail ArgumentError, 'No block given' unless block_given?
18+
19+
Enumerator.new do |y|
20+
val = initial == NOVALUE ? yield() : initial
21+
22+
loop do
23+
y << val
24+
val = yield(val)
25+
end
2426
end
2527
end
2628
end
@@ -118,7 +120,7 @@ def truncate(unit)
118120
.drop_while { |u| u != unit }
119121
.drop(1)
120122
.then { |keys| Units::DEFAULTS.slice(*keys) }
121-
.then(&method(:merge))
123+
.then { |attrs| merge(**attrs) } # can't simplify to &method(:merge) due to 2.7 keyword param problem
122124
end
123125

124126
alias floor truncate

0 commit comments

Comments
 (0)