Sha256: cb607296a9c76beca2a9ce6c984fb770adb19d845a21639b40dd1b002b4ddfd2

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

# Symbol に機能を追加するためのモジュール
# @see http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html
module PositiveSymbolSupport::SymbolExt

  [ :underscore , :camelize , :singularize , :pluralize ,
    :classify , :dasherize ,
    :tableize , :titleize , :titlecase
  ].each do | method_name |
    eval <<-DEF
      def #{method_name.to_s}
        self.to_s.#{method_name.to_s}.to_sym
      end
    DEF
  end

  def constantize
    self
  end

  [ :deconstantize , :demodulize ].each do | instance_method_name |
    eval <<-DEF
      def #{instance_method_name}
        str = to_s.send( __method__ )
        if str.blank?
          nil
        else
          str.to_sym
        end
      end
    DEF
  end

  def foreign_key( separate_class_name_and_id_with_underscore = true )
    to_s.send( __method__ , separate_class_name_and_id_with_underscore ).to_sym
  end

  def humanize( options = {} )
    to_s.send( __method__ , options ).to_sym
  end

  def parameterize( sep = "-" )
    to_s.send( __method__ , sep ).to_sym
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
positive_symbol_support-0.1.2 lib/positive_symbol_support/symbol_ext.rb