Module: Mustermann::ToPattern

Defined in:
lib/mustermann/to_pattern.rb

Overview

Mixin for adding #to_pattern ducktyping to objects.

By default included into String, Symbol, Regexp and Pattern.

Examples:

require 'mustermann/to_pattern'

class Foo
  include Mustermann::ToPattern

  def to_s
    ":foo/:bar"
  end
end

Foo.new.to_pattern # => #<Mustermann::Sinatra:":foo/:bar">

Instance Method Summary collapse

Instance Method Details

#to_pattern(**options) ⇒ Mustermann::Pattern

Converts the object into a Pattern.

Examples:

converting a string

":name.png".to_pattern # => #<Mustermann::Sinatra:":name.png">

converting a string with options

"/*path".to_pattern(type: :rails) # => #<Mustermann::Rails:"/*path">

converting a regexp

/.*/.to_pattern # => #<Mustermann::Regular:".*">

converting a pattern

Mustermann.new("foo").to_pattern # => #<Mustermann::Sinatra:"foo">

Parameters:

  • options (Hash)

    The options hash.

Returns:



37
38
39
# File 'lib/mustermann/to_pattern.rb', line 37

def to_pattern(**options)
  Mustermann.new(self, **options)
end