Skip to content

Commit

Permalink
Update delegate docs with new hash syntax [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosantoniodasilva committed Sep 20, 2012
1 parent 1eef814 commit ed05e92
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions activesupport/lib/active_support/core_ext/module/delegation.rb
Expand Up @@ -18,7 +18,7 @@ class Module
# #
# class Foo < ActiveRecord::Base # class Foo < ActiveRecord::Base
# belongs_to :greeter # belongs_to :greeter
# delegate :hello, :to => :greeter # delegate :hello, to: :greeter
# end # end
# #
# Foo.new.hello # => "hello" # Foo.new.hello # => "hello"
Expand All @@ -28,7 +28,7 @@ class Module
# #
# class Foo < ActiveRecord::Base # class Foo < ActiveRecord::Base
# belongs_to :greeter # belongs_to :greeter
# delegate :hello, :goodbye, :to => :greeter # delegate :hello, :goodbye, to: :greeter
# end # end
# #
# Foo.new.goodbye # => "goodbye" # Foo.new.goodbye # => "goodbye"
Expand All @@ -43,9 +43,9 @@ class Module
# def initialize # def initialize
# @instance_array = [8,9,10,11] # @instance_array = [8,9,10,11]
# end # end
# delegate :sum, :to => :CONSTANT_ARRAY # delegate :sum, to: :CONSTANT_ARRAY
# delegate :min, :to => :@@class_array # delegate :min, to: :@@class_array
# delegate :max, :to => :@instance_array # delegate :max, to: :@instance_array
# end # end
# #
# Foo.new.sum # => 6 # Foo.new.sum # => 6
Expand All @@ -71,7 +71,7 @@ class Module
# Person = Struct.new(:name, :address) # Person = Struct.new(:name, :address)
# #
# class Invoice < Struct.new(:client) # class Invoice < Struct.new(:client)
# delegate :name, :address, :to => :client, :prefix => true # delegate :name, :address, to: :client, prefix: true
# end # end
# #
# john_doe = Person.new('John Doe', 'Vimmersvej 13') # john_doe = Person.new('John Doe', 'Vimmersvej 13')
Expand All @@ -82,7 +82,7 @@ class Module
# It is also possible to supply a custom prefix. # It is also possible to supply a custom prefix.
# #
# class Invoice < Struct.new(:client) # class Invoice < Struct.new(:client)
# delegate :name, :address, :to => :client, :prefix => :customer # delegate :name, :address, to: :client, prefix: :customer
# end # end
# #
# invoice = Invoice.new(john_doe) # invoice = Invoice.new(john_doe)
Expand All @@ -98,7 +98,7 @@ class Module
# def initialize(bar = nil) # def initialize(bar = nil)
# @bar = bar # @bar = bar
# end # end
# delegate :zoo, :to => :bar # delegate :zoo, to: :bar
# end # end
# #
# Foo.new.zoo # raises NoMethodError exception (you called nil.zoo) # Foo.new.zoo # raises NoMethodError exception (you called nil.zoo)
Expand All @@ -108,15 +108,15 @@ class Module
# def initialize(bar = nil) # def initialize(bar = nil)
# @bar = bar # @bar = bar
# end # end
# delegate :zoo, :to => :bar, :allow_nil => true # delegate :zoo, to: :bar, allow_nil: true
# end # end
# #
# Foo.new.zoo # returns nil # Foo.new.zoo # returns nil
# #
def delegate(*methods) def delegate(*methods)
options = methods.pop options = methods.pop
unless options.is_a?(Hash) && to = options[:to] unless options.is_a?(Hash) && to = options[:to]
raise ArgumentError, 'Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, :to => :greeter).' raise ArgumentError, 'Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, to: :greeter).'
end end


prefix, allow_nil = options.values_at(:prefix, :allow_nil) prefix, allow_nil = options.values_at(:prefix, :allow_nil)
Expand Down

0 comments on commit ed05e92

Please sign in to comment.