### Home Classes Methods

### In Files

- lib/facets/random.rb

### Namespace

- MODULE Random::StringExtensions::Self

### Methods

- ::included
- #at_rand
- #at_rand!
- #rand_byte
- #rand_byte!
- #rand_index
- #shuffle
- #shuffle!

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Random
- Random::ArrayExtensions
- Random::HashExtensions
- Random::IntegerExtensions
- Random::NumericExtensions
- Random::RangeExtensions
- Random::StringExtensions
- Random::StringExtensions::Self
- FileUtils
- FileUtils::DryRun
- FileUtils::NoWrite
- FileUtils::Verbose
- Digest
- Digest::Class
- Digest::Instance
- Multiton
- Multiton::Inclusive
- Multiton::MetaMethods
- URI
- URI::Hash
- URI::Kernel
- Argvector
- Argvector
- ERB
- ERB::OpenTemplate
- Enumerable
- Enumerable::Arguments
- GetoptLong
- GetoptLong::DSL
- Memoizable
- Memoizable::Copy
- Numeric
- Numeric::Multipliers
- Object
- Object::ArgVector
- Timer
- Timer::Dummy
- Array
- BasicObject
- CGI
- Cloneable
- Continuation
- Date
- DateTime
- Equitable
- File
- Find
- Hash
- Instantiable
- Integer
- Interval
- Kernel
- Math
- Module
- Net
- NilClass
- NullClass
- OpEsc
- OpenStruct
- Pathname
- Platform
- Range
- RbConfig
- Set
- Shellwords
- String
- StringScanner
- Time
- Tuple
- YAML
- Zlib

No matching classes.

# Random::StringExtensions

### Public Class Methods

included(base) click to toggle source

    # File lib/facets/random.rb, line 337
    def self.included(base)
      base.extend(Self)
    end

### Public Instance Methods

at_rand( separator=// ) click to toggle source

Return a random separation of the string. Default separation is by charaacter.

    "Ruby rules".at_rand(' ')  #~> ["Ruby"]

    # File lib/facets/random.rb, line 369
    def at_rand( separator=// )
      #separator = self.class.patterns( separator )
      self.split(separator,-1).at_rand
    end

at_rand!( separator=// ) click to toggle source

Return a random separation while removing it from the string. Default separation is by character.

    s = "Ruby rules"
    s.at_rand!(' ')    #~> "Ruby"
    s                  #~> "rules"

    # File lib/facets/random.rb, line 381
    def at_rand!( separator=// )
      #separator = self.class.patterns( separator )
      a = self.shatter( separator )
      w = []; a.each_with_index { |s,i| i % 2 == 0 ? w << s : w.last << s }
      i = Random.number(w.size)
      r = w.delete_at( i )
      self.replace( w.join('') )
      return r
    end

rand_byte() click to toggle source

Return a random byte of self.

    "Ruby rules".rand_byte  #~> 121

    # File lib/facets/random.rb, line 395
    def rand_byte
      self[Random.number(size)]
    end

rand_byte!() click to toggle source

Destructive rand_byte. Delete a random byte of self and return it.

    s = "Ruby rules"
    s.rand_byte!      #~> 121
    s                 #~> "Rub rules"

    # File lib/facets/random.rb, line 405
    def rand_byte!
      i = Random.number(size)
      rv = self[i,1]
      self[i,1] = ''
      rv
    end

rand_index() click to toggle source

Return a random string index.

    "Ruby rules".rand_index  #~> 3

    # File lib/facets/random.rb, line 416
    def rand_index
      Random.number(size)
    end

shuffle(separator=//) click to toggle source

Return the string with seperated sections arranged in a random order. The default seperation is by character.

    "Ruby rules".shuffle  #~> "e lybRsuur"

    # File lib/facets/random.rb, line 425
    def shuffle(separator=//)
      split(separator).shuffle.join('')
    end

shuffle!(separator=//) click to toggle source

In place version of shuffle.

    # File lib/facets/random.rb, line 431
    def shuffle!(separator=//)
      self.replace( shuffle(separator) )
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.