0
- # Encapsulates the common pattern of:
0
- # alias_method :foo_without_feature, :foo
0
- # alias_method :foo, :foo_with_feature
0
- # With this, you simply do:
0
- # alias_method_chain :foo, :feature
0
- # And both aliases are set up for you.
0
- # Query and bang methods (foo?, foo!) keep the same punctuation:
0
- # alias_method_chain :foo?, :feature
0
- # alias_method :foo_without_feature?, :foo?
0
- # alias_method :foo?, :foo_with_feature?
0
- # so you can safely chain foo, foo?, and foo! with the same feature.
0
- def alias_method_chain(target, feature)
0
- # Strip out punctuation on predicates or bang methods since
0
- # e.g. target?_without_feature is not a valid method name.
0
- aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
0
- yield(aliased_target, punctuation) if block_given?
0
- with_method, without_method = "#{aliased_target}_with_#{feature}#{punctuation}", "#{aliased_target}_without_#{feature}#{punctuation}"
0
- alias_method without_method, target
0
- alias_method target, with_method
0
- when public_method_defined?(without_method)
0
- when protected_method_defined?(without_method)
0
- when private_method_defined?(without_method)
0
+ # Encapsulates the common pattern of:
0
+ # alias_method :foo_without_feature, :foo
0
+ # alias_method :foo, :foo_with_feature
0
+ # With this, you simply do:
0
+ # alias_method_chain :foo, :feature
0
+ # And both aliases are set up for you.
0
+ # Query and bang methods (foo?, foo!) keep the same punctuation:
0
+ # alias_method_chain :foo?, :feature
0
+ # alias_method :foo_without_feature?, :foo?
0
+ # alias_method :foo?, :foo_with_feature?
0
+ # so you can safely chain foo, foo?, and foo! with the same feature.
0
+ def alias_method_chain(target, feature)
0
+ # Strip out punctuation on predicates or bang methods since
0
+ # e.g. target?_without_feature is not a valid method name.
0
+ aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
0
+ yield(aliased_target, punctuation) if block_given?
0
+ with_method, without_method = "#{aliased_target}_with_#{feature}#{punctuation}", "#{aliased_target}_without_#{feature}#{punctuation}"
0
- # Allows you to make aliases for attributes, which includes
0
- # getter, setter, and query methods.
0
- # class Content < ActiveRecord::Base
0
- # # has a title attribute
0
- # class Email < Content
0
- # alias_attribute :subject, :title
0
- # e.title # => "Superstars"
0
- # e.subject # => "Superstars"
0
- # e.subject? # => true
0
- # e.subject = "Megastars"
0
- # e.title # => "Megastars"
0
- def alias_attribute(new_name, old_name)
0
- module_eval <<-STR, __FILE__, __LINE__+1
0
- def #{new_name}; self.#{old_name}; end
0
- def #{new_name}?; self.#{old_name}?; end
0
- def #{new_name}=(v); self.#{old_name} = v; end
0
+ alias_method without_method, target
0
+ alias_method target, with_method
0
+ when public_method_defined?(without_method)
0
+ when protected_method_defined?(without_method)
0
+ when private_method_defined?(without_method)
0
+ # Allows you to make aliases for attributes, which includes
0
+ # getter, setter, and query methods.
0
+ # class Content < ActiveRecord::Base
0
+ # # has a title attribute
0
+ # class Email < Content
0
+ # alias_attribute :subject, :title
0
+ # e.title # => "Superstars"
0
+ # e.subject # => "Superstars"
0
+ # e.subject? # => true
0
+ # e.subject = "Megastars"
0
+ # e.title # => "Megastars"
0
+ def alias_attribute(new_name, old_name)
0
+ module_eval <<-STR, __FILE__, __LINE__+1
0
+ def #{new_name}; self.#{old_name}; end
0
+ def #{new_name}?; self.#{old_name}?; end
0
+ def #{new_name}=(v); self.#{old_name} = v; end