Sha256: 69679b87f00daa391c59cebd7e10833d2ca627b20026b0f55f20c35e335d1d20

Contents?: true

Size: 534 Bytes

Versions: 5

Compression:

Stored size: 534 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

    def rand
      self[Kernel.rand(length)]
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
random_text-1.1.0 lib/random_text/random_strings.rb
random_text-1.0.2.2 lib/random_text/random_strings.rb
random_text-1.0.2.1 lib/random_text/random_strings.rb
random_text-1.0.2 lib/random_text/random_strings.rb
random_text-1.0.1 lib/random_text/random_strings.rb