On Sep 24, 12:38 pm, Phrogz <phr... / mac.com> wrote:
> class String
>    def variation( values={} )
>      out = self.dup
>      while out.gsub!( /\(([^())?]+)\)(\?)?/ ){
>        ( $2 && ( rand > 0.5 ) ) ? '' : $1.split( '|' ).random
>      }; end
>      out.gsub!( /:(#{values.keys.join('|')})\b/ ){ values[$1.intern] }
>      out.gsub!( /\s{2,}/, ' ' )
>      out
>    end
> end

Oops, I forgot that this relies on having:

class Array
  def random
    self[ rand( self.length ) ]
  end
end