Sha256: c1347b8baab989b7ff00331385cbec9348e6ffa6b2a8ff1697c53f58685b7e0c
Contents?: true
Size: 1.17 KB
Versions: 20
Compression:
Stored size: 1.17 KB
Contents
class String # Turn a downcased string and capitalize it # so that it can be a class # doc_river #=> DocRiver def camelcase gsub(/(^|_|-)(.)/) { $2.upcase } end # "FooBar".snake_case #=> "foo_bar" def snake_case gsub(/\B[A-Z]+/, '_\&').downcase end # "FooBar".dasherize #=> "foo-bar" def dasherize gsub(/\B[A-Z]+/, '-\&').downcase end # Turn a string from lowercased with a . # to a classified classname # rice_and_beans #=> "RiceAndBeans" # handles subclassed and namespaced classes as well # for instance # rice::and::beans #=> Rice::And::Beans def classify self.sub(/.*\./, '').split("::").map {|ele| ele.camelcase }.join("::") end # Constantize tries to find a declared constant with the name specified # in the string. It raises a NameError when the name is not in CamelCase # or is not initialized. # # Examples # "Module".constantize #=> Module # "Class".constantize #=> Class def constantize(mod=Object) camelcased_word = classify begin mod.module_eval(camelcased_word, __FILE__, __LINE__) rescue NameError nil end end def /(o) File.join(self, o.to_s) end end
Version data entries
20 entries across 20 versions & 1 rubygems