Class: RandomlyGenerated::String

Inherits:
Object
  • Object
show all
Defined in:
lib/randomly_generated/string.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 = {}) ⇒ String

Returns a new instance of String.



4
5
6
7
8
# File 'lib/randomly_generated/string.rb', line 4

def initialize(options={})
  super
  @length = options.fetch(:length) { (1..5000) }
  @length = rand.rand(@length) if @length.is_a?(Range)
end

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



2
3
4
# File 'lib/randomly_generated/string.rb', line 2

def length
  @length
end

Instance Method Details

#callObject



10
11
12
# File 'lib/randomly_generated/string.rb', line 10

def call
  @value ||= rand.bytes(length) # TODO: This doesn't handle Unicode characters, only code points 0-255.
end