Module: Concurrent::Utility::NativeInteger
- Extended by:
- NativeInteger
- Included in:
- NativeInteger
- Defined in:
- lib/concurrent-ruby/concurrent/utility/native_integer.rb
Constant Summary collapse
- MIN_VALUE =
- 2))
- MAX_VALUE =
(2**(0.size * 8 - 2) - 1)
Instance Method Summary collapse
- #ensure_integer(value) ⇒ Object
- #ensure_integer_and_bounds(value) ⇒ Object
- #ensure_lower_bound(value) ⇒ Object
- #ensure_positive(value) ⇒ Object
- #ensure_positive_and_no_zero(value) ⇒ Object
- #ensure_upper_bound(value) ⇒ Object
Instance Method Details
#ensure_integer(value) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/concurrent-ruby/concurrent/utility/native_integer.rb', line 23 def ensure_integer(value) unless value.is_a?(Integer) raise ArgumentError.new("#{value} is not an Integer") end value end |
#ensure_integer_and_bounds(value) ⇒ Object
30 31 32 33 34 |
# File 'lib/concurrent-ruby/concurrent/utility/native_integer.rb', line 30 def ensure_integer_and_bounds(value) ensure_integer value ensure_upper_bound value ensure_lower_bound value end |
#ensure_lower_bound(value) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/concurrent-ruby/concurrent/utility/native_integer.rb', line 16 def ensure_lower_bound(value) if value < MIN_VALUE raise RangeError.new("#{value} is less than the maximum value of #{MIN_VALUE}") end value end |
#ensure_positive(value) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/concurrent-ruby/concurrent/utility/native_integer.rb', line 36 def ensure_positive(value) if value < 0 raise ArgumentError.new("#{value} cannot be negative") end value end |
#ensure_positive_and_no_zero(value) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/concurrent-ruby/concurrent/utility/native_integer.rb', line 43 def ensure_positive_and_no_zero(value) if value < 1 raise ArgumentError.new("#{value} cannot be negative or zero") end value end |