diff options
Diffstat (limited to 'activesupport/lib/active_support/core_ext/module')
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/attribute_accessors.rb | 12 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/delegation.rb | 8 |
2 files changed, 16 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb index 58ff363244..51e1c9af90 100644 --- a/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb +++ b/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb @@ -1,6 +1,16 @@ # Extends the module object with module and instance accessors for class attributes, # just like the native attr* accessors for instance attributes. -class Module # :nodoc: +# +# module AppConfiguration +# mattr_accessor :google_api_key +# self.google_api_key = "123456789" +# +# mattr_accessor :paypal_url +# self.paypal_url = "www.sandbox.paypal.com" +# end +# +# AppConfiguration.google_api_key = "overriding the api key!" +class Module def mattr_reader(*syms) syms.each do |sym| next if sym.is_a?(Hash) diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index f6647eaed3..e0b5f3e379 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -1,8 +1,8 @@ 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 :to option (also a symbol - # or string). At least one method and the :to option are required. + # 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. # # Delegation is particularly useful with Active Record associations: # @@ -20,6 +20,7 @@ class Module # Foo.new.goodbye # => NoMethodError: undefined method `goodbye' for #<Foo:0x1af30c> # # Multiple delegates to the same target are allowed: + # # class Foo < ActiveRecord::Base # belongs_to :greeter # delegate :hello, :goodbye, :to => :greeter @@ -28,7 +29,8 @@ class Module # Foo.new.goodbye # => "goodbye" # # Methods can be delegated to instance variables, class variables, or constants - # by providing the variable as a symbol: + # by providing them as a symbols: + # # class Foo # CONSTANT_ARRAY = [0,1,2,3] # @@class_array = [4,5,6,7] |