Class: RandomlyGenerated::String
- Defined in:
- lib/randomly_generated/string.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
Attributes inherited from Object
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(options = {}) ⇒ String
constructor
A new instance of String.
Methods inherited from Object
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(={}) super @length = .fetch(:length) { (1..5000) } @length = rand.rand(@length) if @length.is_a?(Range) end |
Instance Attribute Details
#length ⇒ Object (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
#call ⇒ Object
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 |