String (Class)

In: rand.rb
Parent: Object

Public Instance methods

Return a random byte of self.

  "Ruby rules".pick_byte  #=> 121

[Source]

     # File rand.rb, line 185
185:   def pick_byte
186:     self[pick_index]
187:   end

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

  s = "Ruby rules"
  s.pick_byte!  #=> 121
  s             #=> "Rub rules"

[Source]

     # File rand.rb, line 211
211:   def pick_byte!
212:     pick_char![0]
213:   end

Return a single-character string of a random character in self.

  "Ruby rules".pick_char  #=> "y"

[Source]

     # File rand.rb, line 191
191:   def pick_char
192:     pick_byte.chr
193:   end

Destructive pick_char. Delete a random character of the string and return it as a single-character string.

  s = "Ruby rules"
  s.pick_char!  #=> "y"
  s             #=> "Rub rules"

[Source]

     # File rand.rb, line 200
200:   def pick_char!
201:     i = pick_index
202:     rv = self[i,1]
203:     self[i,1] = ""
204:     rv
205:   end

Return a random byte index of self.

  "Ruby rules".pick_index  #=> 3

[Source]

     # File rand.rb, line 217
217:   def pick_index
218:     rand(size)
219:   end

Destructive pick_index. Delete a random byte of self and return it’s index.

  s = "Ruby rules"
  s.pick_index  #=> 3
  s             #=> "Rub rules"

[Source]

     # File rand.rb, line 226
226:   def pick_index!
227:     i = pick_index
228:     self[i,1] = ""
229:     i
230:   end

Return the string with characters arranged in random order.

  "Ruby rules".shuffle_chars  #=> "e lybRsuur"

[Source]

     # File rand.rb, line 170
170:   def shuffle_chars
171:     split(//).shuffle.join('')
172:   end

Destructive shuffle_chars. Arrange the characters of the string in new, random order.

  s = "Ruby rules".shuffle_chars
  s.shuffle_chars!
  s    #=> "e lybRsuur"

[Source]

     # File rand.rb, line 179
179:   def shuffle_chars!
180:     self[0,size] = shuffle_chars
181:   end

[Validate]