Sha256: 32b9acc508c057c91828b371ddc4cc229cedeb5c550a645b11c53035c863f8dd

Contents?: true

Size: 1.2 KB

Versions: 9

Compression:

Stored size: 1.2 KB

Contents

class Forgery
  module Extensions
    class String < ::String

      def unextend
        to_s
      end

      def to_numbers(replace='#')
        gsub(/#{replace}/){ Kernel.rand(10) }
      end

      # Ripped right out of rails
      def camelize(first_letter = :upper)
        case first_letter
        when :upper
          to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
        when :lower
          first.downcase + camelize(self)[1..-1]
        end
      end

      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_get(name, false) || constant.const_missing(name)
          end
          constant
        end
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
forgery-0.8.1 lib/forgery/extensions/string.rb
forgery-0.7.0 lib/forgery/extensions/string.rb
forgery-0.6.0 lib/forgery/extensions/string.rb
forgery-0.5.0 lib/forgery/extensions/string.rb
forgery-0.4.4 lib/forgery/extensions/string.rb
forgery-0.4.3 lib/forgery/extensions/string.rb
forgery-0.4.2 lib/forgery/extensions/string.rb
forgery-0.4.1 lib/forgery/extensions/string.rb
forgery-0.4.0 lib/forgery/extensions/string.rb