lib/merb/merb_utils.rb in merb-0.0.4 vs lib/merb/merb_utils.rb in merb-0.0.5

- old
+ new

@@ -1,29 +1,38 @@ class String + + # reloads controller classes on each request if + # :allow_reloading is set to true in the config + # file or command line options. def import Merb::Server.config[:allow_reloading] ? load( self.snake_case + '.rb' ) : require( self.snake_case ) end + # "FooBar".snake_case #=> "foo_bar" def snake_case return self unless self =~ %r/[A-Z]/ self.reverse.scan(%r/[A-Z]+|[^A-Z]*[A-Z]+?/).reverse.map{|word| word.reverse.downcase}.join '_' end - + # "foo_bar".camel_case #=> "FooBar" def camel_case return self if self =~ %r/[A-Z]/ and self !~ %r/_/ words = self.strip.split %r/\s*_+\s*/ words.map!{|w| w.downcase.sub(%r/^./){|c| c.upcase}} words.join end end class Symbol + + # faster Symbol#to_s to speed up routing. def to_s @str_rep || (@str_rep = id2name.freeze) end + + # ["foo", "bar"].map &:reverse #=> ['oof', 'rab'] def to_proc Proc.new{|*args| args.shift.__send__(self, *args)} end end @@ -38,9 +47,10 @@ def with_indifferent_access MerbHash.new(self) end end +# like HashWithIndifferentAccess from ActiveSupport. class MerbHash < Hash def initialize(constructor = {}) if constructor.is_a?(Hash) super() update(constructor)