mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
adding documentation to ActiveSupport::Concern ht:strictly typed for an awesome example
some minor documentation changes
This commit is contained in:
parent
7745f716a1
commit
589e6977d7
3 changed files with 40 additions and 1 deletions
|
@ -61,6 +61,8 @@ module ActiveModel
|
||||||
# person.serializable_hash # => {"name"=>"Bob"}
|
# person.serializable_hash # => {"name"=>"Bob"}
|
||||||
# person.to_json # => "{\"name\":\"Bob\"}"
|
# person.to_json # => "{\"name\":\"Bob\"}"
|
||||||
# person.to_xml # => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<serial-person...
|
# person.to_xml # => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<serial-person...
|
||||||
|
#
|
||||||
|
# Valid options are <tt>:only</tt>, <tt>:except</tt> and <tt>:methods</tt> .
|
||||||
module Serialization
|
module Serialization
|
||||||
def serializable_hash(options = nil)
|
def serializable_hash(options = nil)
|
||||||
options ||= {}
|
options ||= {}
|
||||||
|
|
|
@ -568,7 +568,9 @@ module ActiveSupport
|
||||||
#
|
#
|
||||||
# would trigger <tt>Audit#before_save</tt> instead. That's constructed by calling
|
# would trigger <tt>Audit#before_save</tt> instead. That's constructed by calling
|
||||||
# <tt>"#{kind}_#{name}"</tt> on the given instance. In this case "kind" is "before" and
|
# <tt>"#{kind}_#{name}"</tt> on the given instance. In this case "kind" is "before" and
|
||||||
# "name" is "save".
|
# "name" is "save". In this context treat ":kind" and ":name" as special thing where
|
||||||
|
# ":kind" refers to "callback type(before/after)" and ":name" refers to the method on
|
||||||
|
# which callbacks are being defined.
|
||||||
#
|
#
|
||||||
# A declaration like
|
# A declaration like
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,3 +1,38 @@
|
||||||
|
# A typical module looks like this
|
||||||
|
#
|
||||||
|
# module M
|
||||||
|
# def self.included(base)
|
||||||
|
# base.send(:extend, ClassMethods)
|
||||||
|
# base.send(:include, InstanceMethods)
|
||||||
|
# scope :foo, :conditions => {:created_at => nil}
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# module ClassMethods
|
||||||
|
# def cm; puts 'I am class method'; end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# module InstanceMethods
|
||||||
|
# def im; puts 'I am instance method'; end
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# By using <tt>ActiveSupport::Concern</tt> above module could be written as:
|
||||||
|
#
|
||||||
|
# module M
|
||||||
|
# extend ActiveSupport::Concern
|
||||||
|
#
|
||||||
|
# included do
|
||||||
|
# scope :foo, :conditions => {:created_at => nil}
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# module ClassMethods
|
||||||
|
# def cm; puts 'I am class method'; end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# module InstanceMethods
|
||||||
|
# def im; puts 'I am instance method'; end
|
||||||
|
# end
|
||||||
|
# end
|
||||||
module ActiveSupport
|
module ActiveSupport
|
||||||
module Concern
|
module Concern
|
||||||
def self.extended(base)
|
def self.extended(base)
|
||||||
|
|
Loading…
Reference in a new issue