Sha256: 0d2dfe1b6fb5f74a1322880a186fd8b66f9a151a4068259cd93ca3cf6055df59

Contents?: true

Size: 550 Bytes

Versions: 3

Compression:

Stored size: 550 Bytes

Contents

module Cell::Util
  def util
    Inflector
  end

  class Inflector
    # copied from ActiveSupport.
    def self.underscore(constant)
      constant.gsub(/::/, '/').
      gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
      gsub(/([a-z\d])([A-Z])/,'\1_\2').
      tr("-", "_").
      downcase
    end

    # WARNING: this API might change.
    def self.constant_for(name)
      class_name = name.split("/").collect do |part|
        part.split('_').collect(&:capitalize).join
      end.join('::')
      
      Object.const_get(class_name)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cells-4.1.4 lib/cell/util.rb
cells-4.1.3 lib/cell/util.rb
cells-4.1.2 lib/cell/util.rb