Sha256: 01ae06c8e183bb0691a855c52ce809fba1b90bff8ca3600261c21b6363820040

Contents?: true

Size: 557 Bytes

Versions: 4

Compression:

Stored size: 557 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, false)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cells-4.1.8 lib/cell/util.rb
cells-4.1.7 lib/cell/util.rb
cells-4.1.6 lib/cell/util.rb
cells-4.1.5 lib/cell/util.rb