Class: RandomText::Randomized

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

Instance Method Summary collapse

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

#getObject



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