- Timestamp:
- 12/05/07 21:45:35 (9 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/lib/active_support/core_ext/module/delegation.rb
r7236 r8311 6 6 # 7 7 # Delegation is particularly useful with Active Record associations: 8 # 8 9 # class Greeter < ActiveRecord::Base 9 10 # def hello() "hello" end … … 26 27 # 27 28 # Foo.new.goodbye # => "goodbye" 29 # 30 # Methods can be delegated to instance variables, class variables, or constants 31 # by providing the variable as a symbol: 32 # class Foo 33 # CONSTANT_ARRAY = [0,1,2,3] 34 # @@class_array = [4,5,6,7] 35 # 36 # def initialize 37 # @instance_array = [8,9,10,11] 38 # end 39 # delegate :sum, :to => :CONSTANT_ARRAY 40 # delegate :min, :to => :@@class_array 41 # delegate :max, :to => :@instance_array 42 # end 43 # 44 # Foo.new.sum # => 6 45 # Foo.new.min # => 4 46 # Foo.new.max # => 11 47 # 28 48 def delegate(*methods) 29 49 options = methods.pop