Sha256: 86d2ebd98f3d651436442d136da36f042c1c65dbf47b93059f0c08d752baab36

Contents?: true

Size: 480 Bytes

Versions: 6

Compression:

Stored size: 480 Bytes

Contents

module RandomText
  class RandomStrings < Array
    def get(count = nil)
      case count
      when :all
        to_a.sort_by{ Kernel.rand }
      when Integer
        Array.new(count){ rand }
      else
        rand
      end
    end

    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
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
random_text-0.0.6.5 lib/random_text/random_strings.rb
random_text-0.0.6 lib/random_text/random_strings.rb
random_text-0.0.6.1 lib/random_text/random_strings.rb
random_text-0.0.6.2 lib/random_text/random_strings.rb
random_text-0.0.6.3 lib/random_text/random_strings.rb
random_text-0.0.6.4 lib/random_text/random_strings.rb