Sha256: 6ba2864d6237d2581e141cb105e8427c77ab7773e6aa9940886bc090349ddc7b

Contents?: true

Size: 567 Bytes

Versions: 2

Compression:

Stored size: 567 Bytes

Contents

module Pallets
  module Util
    extend self

    def camelize(str)
      str.to_s.gsub(/(?:^|_)([a-z])/) { $1.upcase }
    end

    def constantize(str)
      names = str.split('::')

      # Raise the "usual" NameError
      Object.const_get(str) if names.empty?

      # Handle "::Const" cases
      names.shift if names.first.empty?

      names.inject(Object) do |constant, name|
        if constant.const_defined?(name, false)
          constant.const_get(name, false)
        else
          constant.const_missing(name)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pallets-0.3.0 lib/pallets/util.rb
pallets-0.2.0 lib/pallets/util.rb