Sha256: 3e5fc6b0ef85de5ae960f63e213f2c8e82363457edd3706c9070cfca954a92b1
Contents?: true
Size: 1.07 KB
Versions: 1
Compression:
Stored size: 1.07 KB
Contents
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 if Merb::Server.config[:allow_reloading] Object.send(:remove_const, self.camel_case.intern) rescue nil load(self.snake_case + '.rb') else require(self.snake_case) end 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 # Concatenates a path def /(o) File.join(self, o.to_s) end def to_const const = const.to_s.dup base = const.sub!(/^::/, '') ? Object : ( self.kind_of?(Module) ? self : self.class ) const.split(/::/).inject(base){ |mod, name| mod.const_get(name) } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
merb-0.0.8 | lib/merb/core_ext/merb_string.rb |