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
24 25 26 27 28 29 |
# File 'lib/concurrent-ruby/concurrent/utility/native_integer.rb', line 24 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
31 32 33 34 35 |
# File 'lib/concurrent-ruby/concurrent/utility/native_integer.rb', line 31 def ensure_integer_and_bounds(value) ensure_integer value ensure_upper_bound value ensure_lower_bound value end |
#ensure_lower_bound(value) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/concurrent-ruby/concurrent/utility/native_integer.rb', line 17 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
37 38 39 40 41 42 |
# File 'lib/concurrent-ruby/concurrent/utility/native_integer.rb', line 37 def ensure_positive(value) if value < 0 raise ArgumentError.new("#{value} cannot be negative") end value end |
#ensure_positive_and_no_zero(value) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/concurrent-ruby/concurrent/utility/native_integer.rb', line 44 def ensure_positive_and_no_zero(value) if value < 1 raise ArgumentError.new("#{value} cannot be negative or zero") end value end |