Skip to content

Commit 32162e0

Browse files
committed
Extract ruby_version comparison
1 parent 8c92b51 commit 32162e0

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

ext/concurrent/extconf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def create_dummy_makefile
1111
end
1212
end
1313

14-
if defined?(JRUBY_VERSION) || ! Concurrent.allow_c_extensions?
14+
if Concurrent.on_jruby? || ! Concurrent.allow_c_extensions?
1515
create_dummy_makefile
1616
warn 'C optimizations are not supported on this version of Ruby.'
1717
else

lib/concurrent/synchronization/object.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ module Synchronization
33
Implementation = case
44
when Concurrent.on_jruby?
55
JavaObject
6-
when Concurrent.on_cruby? && (RUBY_VERSION.split('.').map(&:to_i) <=> [1, 9, 3]) <= 0
6+
when Concurrent.on_cruby? && Concurrent.ruby_version(:<=, 1, 9, 3)
77
MonitorObject
8-
when Concurrent.on_cruby?
8+
when Concurrent.on_cruby? && Concurrent.ruby_version(:>, 1, 9, 3)
99
MutexObject
1010
when Concurrent.on_rbx?
1111
RbxObject
1212
else
13+
warn 'Possibly unsupported Ruby implementation'
1314
MutexObject
1415
end
1516
private_constant :Implementation

lib/concurrent/utility/engine.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ def on_rbx?
1616
def ruby_engine
1717
defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
1818
end
19+
20+
def ruby_version(comparison, major, minor, patch)
21+
result = (RUBY_VERSION.split('.').map(&:to_i) <=> [major, minor, patch])
22+
comparisons = { :== => [0],
23+
:>= => [1, 0],
24+
:<= => [-1, 0],
25+
:> => [1],
26+
:< => [-1] }
27+
comparisons.fetch(comparison).include? result
28+
end
1929
end
2030

2131
extend EngineDetector

0 commit comments

Comments
 (0)