Ticket #7184: doc_for_delegate.diff
| File doc_for_delegate.diff, 1.1 kB (added by dcmanges, 2 years ago) |
|---|
-
lib/active_support/core_ext/module/delegation.rb
old new 20 20 # 21 21 # Multiple delegates to the same target are allowed: 22 22 # class Foo < ActiveRecord::Base 23 # belongs_to :greeter 23 24 # delegate :hello, :goodbye, :to => :greeter 24 25 # end 25 26 # 26 27 # Foo.new.goodbye # => "goodbye" 28 # 29 # Methods can be delegated to instance variables, class variables, or constants 30 # by providing the variable as a symbol: 31 # class Foo 32 # CONSTANT_ARRAY = [0,1,2,3] 33 # @@class_array = [4,5,6,7] 34 # 35 # def initialize 36 # @instance_array = [8,9,10,11] 37 # end 38 # delegate :sum, :to => :CONSTANT_ARRAY 39 # delegate :min, :to => :@@class_array 40 # delegate :max, :to => :@instance_array 41 # end 42 # 43 # Foo.new.sum # => 6 44 # Foo.new.min # => 4 45 # Foo.new.max # => 11 46 # 27 47 def delegate(*methods) 28 48 options = methods.pop 29 49 unless options.is_a?(Hash) && to = options[:to]