Module: CoffeeTable::Utility

Included in:
Cache, Key
Defined in:
lib/coffee_table/utility.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *arguments, &block) ⇒ Object

used for setting default options



5
6
7
8
9
10
11
12
# File 'lib/coffee_table/utility.rb', line 5

def method_missing(method_sym, *arguments, &block)
  if method_sym.to_s =~ /^default_(.*)_to$/
    tag_name = method_sym.to_s.split("_")[1..-2].join("_").to_sym
    @options[tag_name] = arguments[0] unless @options.has_key?(tag_name)
  else
    super
  end
end

Instance Method Details

#underscore(text) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/coffee_table/utility.rb', line 14

def underscore(text)
  text.gsub(/::/, '/').
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
  tr("-", "_").
  downcase
end