Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/bently/core_ext/string.rb
Overview
some methods borrowed from ActiveSupport github.com/rails/rails/tree/master/activesupport MIT License (www.opensource.org/licenses/MIT)
Instance Method Summary collapse
Instance Method Details
#camelize ⇒ Object
7 8 9 10 11 12 |
# File 'lib/bently/core_ext/string.rb', line 7 def camelize string = self string = string.sub(/^[a-z\d]*/) { $&.capitalize } string = string.gsub(/\-/,'_') string.gsub(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }.gsub('/', '::') end |
#constantize ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bently/core_ext/string.rb', line 15 def constantize names = self.split('::') names.shift if names.empty? || names.first.empty? constant = Object names.each do |name| constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name) end constant end |