mirror of
https://github.com/jimeh/skyhook.git
synced 2026-02-19 11:06:38 +00:00
initial import
This commit is contained in:
26
init/lib/skyhook/utils/object_overloads.rb
Normal file
26
init/lib/skyhook/utils/object_overloads.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
class Object
|
||||
|
||||
def constantize
|
||||
unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self
|
||||
raise NameError, "#{self.inspect} is not a valid constant name!"
|
||||
end
|
||||
Object.module_eval("::#{$1}", __FILE__, __LINE__)
|
||||
end
|
||||
|
||||
def camelize(first_letter_in_uppercase = true)
|
||||
if first_letter_in_uppercase
|
||||
self.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
||||
else
|
||||
self.first + camelize(lower_case_and_underscored_word)[1..-1]
|
||||
end
|
||||
end
|
||||
|
||||
def underscore
|
||||
self.to_s.gsub(/::/, '/').
|
||||
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
||||
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
||||
tr("-", "_").
|
||||
downcase
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user