Class Hashie::Rash
In: lib/hashie/rash.rb
Parent: Object

Rash is a Hash whose keys can be Regexps, or Ranges, which will match many input keys.

A good use case for this class is routing URLs in a web framework. The Rash‘s keys match URL patterns, and the values specify actions which can handle the URL. When the Rash‘s value is proc, the proc will be automatically called with the regexp‘s matched groups as block arguments.

Usage example:

    greeting = Hashie::Rash.new( /^Mr./ => "Hello sir!", /^Mrs./ => "Evening, madame." )
    greeting["Mr. Steve Austin"] #=> "Hello sir!"
    greeting["Mrs. Steve Austin"] #=> "Evening, madame."

Note: The Rash is automatically optimized every 500 accesses

      (Regexps get sorted by how often they get matched).
      If this is too low or too high, you can tune it by
      setting: `rash.optimize_every = n`

Methods

[]   []=   all   fetch   method_missing   new   respond_to_missing?   update  

Attributes

optimize_every  [RW] 

Public Class methods

Public Instance methods

Return the first thing that matches the key.

Return everything that matches the query.

Raise (or yield) unless something matches the key.

[Validate]