Class: Hobby::Router::Routes
- Inherits:
-
Hash
- Object
- Hash
- Hobby::Router::Routes
- Defined in:
- lib/hobby/router/routes.rb
Instance Method Summary collapse
- #[]=(key, route) ⇒ Object
-
#initialize ⇒ Routes
constructor
A new instance of Routes.
Constructor Details
#initialize ⇒ Routes
Returns a new instance of Routes.
3 4 5 6 |
# File 'lib/hobby/router/routes.rb', line 3 def initialize @patterns = {} super { |hash, key| hash[key] = find key } end |
Instance Method Details
#[]=(key, route) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/hobby/router/routes.rb', line 8 def []= key, route if key.include? ?: string = key.gsub(/(:\w+)/) { "(?<#{$1[1..-1]}>[^/?#.]+)" } @patterns[/^#{string}$/] = route else super and super "#{key}/", route end end |