Class: RandomText::Randomized
- Inherits:
-
Object
- Object
- RandomText::Randomized
- Defined in:
- lib/random_text.rb
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(data) ⇒ Randomized
constructor
A new instance of Randomized.
- #unique(n) ⇒ Object
Constructor Details
#initialize(data) ⇒ Randomized
Returns a new instance of Randomized.
8 9 10 |
# File 'lib/random_text.rb', line 8 def initialize(data) @list = data end |
Instance Method Details
#get ⇒ Object
11 12 13 14 15 |
# File 'lib/random_text.rb', line 11 def get s = @list.slice!(rand(@list.length)) @list << s s end |
#unique(n) ⇒ Object
16 17 18 19 |
# File 'lib/random_text.rb', line 16 def unique(n) raise "Dictionary has only #{@list.length} elements (you asked for n)" if n > @list.length @list.sort{ rand - 0.5 }.slice(0, n) end |