Method: Verbal#otherwise

Defined in:
lib/verbal.rb

#otherwise(value = nil) ⇒ Object

Adds a alternative expression to be matched.

Examples:

Tests if the string begins with ‘http://’ or ‘ftp://’

link = 'ftp://ftp.google.com/';
verbal = Verbal.new do
  find 'http'
  maybe 's'
  find '://'
  otherwise
  find 'ftp://'
end
link =~ verbal # => 0


194
195
196
197
198
199
# File 'lib/verbal.rb', line 194

def otherwise(value = nil)
  @prefixes += "(?:"
  @suffixes = ")" + @suffixes
  append(")|(?:")
  find(value) if value
end