Class: RandomlyGenerated::Integer
- Defined in:
- lib/randomly_generated/integer.rb
Instance Attribute Summary collapse
-
#maximum ⇒ Object
readonly
Returns the value of attribute maximum.
-
#minimum ⇒ Object
readonly
Returns the value of attribute minimum.
Attributes inherited from Object
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(options = {}) ⇒ Integer
constructor
A new instance of Integer.
Methods inherited from Object
Constructor Details
#initialize(options = {}) ⇒ Integer
Returns a new instance of Integer.
14 15 16 17 18 19 |
# File 'lib/randomly_generated/integer.rb', line 14 def initialize(={}) super [:range] ||= Integer::MIN..Integer::MAX @minimum = .fetch(:minimum) { .fetch(:range).first } @maximum = .fetch(:maximum) { .fetch(:range).last } end |
Instance Attribute Details
#maximum ⇒ Object (readonly)
Returns the value of attribute maximum.
12 13 14 |
# File 'lib/randomly_generated/integer.rb', line 12 def maximum @maximum end |
#minimum ⇒ Object (readonly)
Returns the value of attribute minimum.
11 12 13 |
# File 'lib/randomly_generated/integer.rb', line 11 def minimum @minimum end |
Instance Method Details
#call ⇒ Object
21 22 23 24 |
# File 'lib/randomly_generated/integer.rb', line 21 def call # TODO: We should weight this to make more "special edge-case" results show up -- like 0, 1, Integer::MAX, etc. @value ||= rand.rand(minimum..maximum) end |