Class: RandomlyGenerated::Integer

Inherits:
Object
  • Object
show all
Defined in:
lib/randomly_generated/integer.rb

Instance Attribute Summary collapse

Attributes inherited from Object

#rand, #seed

Instance Method Summary collapse

Methods inherited from Object

#shrunken_subsets

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(options={})
  super
  options[:range] ||= Integer::MIN..Integer::MAX
  @minimum = options.fetch(:minimum) { options.fetch(:range).first }
  @maximum = options.fetch(:maximum) { options.fetch(:range).last }
end

Instance Attribute Details

#maximumObject (readonly)

Returns the value of attribute maximum.



12
13
14
# File 'lib/randomly_generated/integer.rb', line 12

def maximum
  @maximum
end

#minimumObject (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

#callObject



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