Module | ActiveSupport::CoreExtensions::Module |
In: |
lib/active_support/core_ext/module.rb
lib/active_support/core_ext/module/aliasing.rb lib/active_support/core_ext/module/model_naming.rb lib/active_support/core_ext/module/introspection.rb |
Various extensions for the Ruby core Module class.
Allows you to make aliases for attributes, which includes getter, setter, and query methods.
Example:
class Content < ActiveRecord::Base # has a title attribute end class Email < Content alias_attribute :subject, :title end e = Email.find(1) e.title # => "Superstars" e.subject # => "Superstars" e.subject? # => true e.subject = "Megastars" e.title # => "Megastars"
Encapsulates the common pattern of:
alias_method :foo_without_feature, :foo alias_method :foo, :foo_with_feature
With this, you simply do:
alias_method_chain :foo, :feature
And both aliases are set up for you.
Query and bang methods (foo?, foo!) keep the same punctuation:
alias_method_chain :foo?, :feature
is equivalent to
alias_method :foo_without_feature?, :foo? alias_method :foo?, :foo_with_feature?
so you can safely chain foo, foo?, and foo! with the same feature.
Returns the names of the constants defined locally rather than the constants themselves. See local_constants.
Returns the constants that have been defined locally by this object and not in an ancestor. This method is exact if running under Ruby 1.9. In previous versions it may miss some constants if their definition in some ancestor is identical to their definition in the receiver.
Returns an ActiveSupport::ModelName object for module. It can be used to retrieve all kinds of naming-related information.