Class: RandomText::RandomStrings
- Inherits:
-
Array
- Object
- Array
- RandomText::RandomStrings
- Defined in:
- lib/random_text/random_strings.rb
Instance Method Summary collapse
Instance Method Details
#get(count = nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/random_text/random_strings.rb', line 3 def get(count = nil) case count when :all to_a.sort_by{ Kernel.rand } when Integer Array.new(count){ rand } else rand end end |
#rand ⇒ Object
24 25 26 |
# File 'lib/random_text/random_strings.rb', line 24 def rand self[Kernel.rand(length)] end |
#uniq(count) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/random_text/random_strings.rb', line 14 def uniq(count) case count when :all get(:all) when Integer raise "Dictionary has only #{length} elements (you asked for n)" if count > length get(:all).slice(0, count) end end |