Sha256: f540672e47e17a9aee6404c7cd526ac7eea1d8c65e628c0c1d31f7c892334a2c

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

module Jackb
  module String
    def self.included(klass)
      klass.class_eval do
        def camelize
          self.split(/[^a-z0-9]/i).map{|w| w.capitalize}.join
        end
        
        
        # Ruby 1.9 introduces an inherit argument for Module#const_get and
        # #const_defined? and changes their default behavior.
        # Taken from rails' inflectors. http://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/methods.rb
        if Module.method(:const_get).arity == 1
          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
        else
          def constantize
            names = self.split('::')
            names.shift if names.empty? || names.first.empty?
    
            constant = Object
            names.each do |name|
              constant = constant.const_defined?(name, false) ? constant.const_get(name) : constant.const_missing(name)
            end
            constant
          end
        end
      end
    end
  end
end
String.send(:include, Jackb::String)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jackb-0.0.4 lib/jackb/string.rb