diff options
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/delegation.rb | 21 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/introspection.rb | 16 |
2 files changed, 21 insertions, 16 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index df8aefea5a..381181b2f4 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -1,14 +1,19 @@ class Module # Provides a delegate class method to easily expose contained objects' methods # as your own. Pass one or more methods (specified as symbols or strings) - # and the name of the target object as the final <tt>:to</tt> option (also a symbol - # or string). At least one method and the <tt>:to</tt> option are required. + # and the name of the target object via the <tt>:to</tt> option (also a symbol + # or string). At least one method and the <tt>:to</tt> option are required. # # Delegation is particularly useful with Active Record associations: # # class Greeter < ActiveRecord::Base - # def hello() "hello" end - # def goodbye() "goodbye" end + # def hello + # "hello" + # end + # + # def goodbye + # "goodbye" + # end # end # # class Foo < ActiveRecord::Base @@ -72,9 +77,9 @@ class Module # invoice.customer_name # => "John Doe" # invoice.customer_address # => "Vimmersvej 13" # - # If the object to which you delegate can be nil, you may want to use the - # :allow_nil option. In that case, it returns nil instead of raising a - # NoMethodError exception: + # If the delegate object is +nil+ an exception is raised, and that happens + # no matter whether +nil+ responds to the delegated method. You can get a + # +nil+ instead with the +:allow_nil+ option. # # class Foo # attr_accessor :bar @@ -124,7 +129,7 @@ class Module #{to}.__send__(#{method.inspect}, *args, &block) # client.__send__(:name, *args, &block) rescue NoMethodError # rescue NoMethodError if #{to}.nil? # if client.nil? - #{on_nil} + #{on_nil} # return # depends on :allow_nil else # else raise # raise end # end diff --git a/activesupport/lib/active_support/core_ext/module/introspection.rb b/activesupport/lib/active_support/core_ext/module/introspection.rb index 23a1063901..c08ad251dd 100644 --- a/activesupport/lib/active_support/core_ext/module/introspection.rb +++ b/activesupport/lib/active_support/core_ext/module/introspection.rb @@ -3,7 +3,7 @@ require 'active_support/inflector' class Module # Returns the name of the module containing this one. # - # p M::N.parent_name # => "M" + # M::N.parent_name # => "M" def parent_name unless defined? @parent_name @parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil @@ -19,13 +19,13 @@ class Module # end # X = M::N # - # p M::N.parent # => M - # p X.parent # => M + # M::N.parent # => M + # X.parent # => M # # The parent of top-level and anonymous modules is Object. # - # p M.parent # => Object - # p Module.new.parent # => Object + # M.parent # => Object + # Module.new.parent # => Object # def parent parent_name ? ActiveSupport::Inflector.constantize(parent_name) : Object @@ -40,9 +40,9 @@ class Module # end # X = M::N # - # p M.parents # => [Object] - # p M::N.parents # => [M, Object] - # p X.parents # => [M, Object] + # M.parents # => [Object] + # M::N.parents # => [M, Object] + # X.parents # => [M, Object] # def parents parents = [] |