diff options
author | Leonel Galán <leonel@getstealz.com> | 2017-05-17 15:23:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-17 15:23:21 -0400 |
commit | 0804e58e1e6a52190a950f863622102b6b21ccb8 (patch) | |
tree | a2d9887906bd2c472edc54907362b93a57f52f0f /activesupport/lib/active_support/core_ext/module/delegation.rb | |
parent | f5b2a0ef408f01dd9f12b456f5e4bb41ebb4cb76 (diff) | |
parent | 385d9af299fbfac7f063de214d371545bafef5df (diff) | |
download | rails-0804e58e1e6a52190a950f863622102b6b21ccb8.tar.gz rails-0804e58e1e6a52190a950f863622102b6b21ccb8.tar.bz2 rails-0804e58e1e6a52190a950f863622102b6b21ccb8.zip |
Merge branch 'master' into bug/filtered_parameters_class
Diffstat (limited to 'activesupport/lib/active_support/core_ext/module/delegation.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/delegation.rb | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index 85ab739095..13f3894e6c 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -219,48 +219,43 @@ class Module # When building decorators, a common pattern may emerge: # # class Partition - # def initialize(first_event) - # @events = [ first_event ] + # def initialize(event) + # @event = event # end # - # def people - # if @events.first.detail.people.any? - # @events.collect { |e| Array(e.detail.people) }.flatten.uniq - # else - # @events.collect(&:creator).uniq - # end + # def person + # @event.detail.person || @event.creator # end # # private # def respond_to_missing?(name, include_private = false) - # @events.respond_to?(name, include_private) + # @event.respond_to?(name, include_private) # end # # def method_missing(method, *args, &block) - # @events.send(method, *args, &block) + # @event.send(method, *args, &block) # end # end # - # With `Module#delegate_missing_to`, the above is condensed to: + # With <tt>Module#delegate_missing_to</tt>, the above is condensed to: # # class Partition - # delegate_missing_to :@events + # delegate_missing_to :@event # - # def initialize(first_event) - # @events = [ first_event ] + # def initialize(event) + # @event = event # end # - # def people - # if @events.first.detail.people.any? - # @events.collect { |e| Array(e.detail.people) }.flatten.uniq - # else - # @events.collect(&:creator).uniq - # end + # def person + # @event.detail.person || @event.creator # end # end # - # The target can be anything callable within the object. E.g. instance - # variables, methods, constants and the likes. + # The target can be anything callable within the object, e.g. instance + # variables, methods, constants, etc. + # + # The delegated method must be public on the target, otherwise it will + # raise +NoMethodError+. def delegate_missing_to(target) target = target.to_s target = "self.#{target}" if DELEGATION_RESERVED_METHOD_NAMES.include?(target) |