Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
delegate method should treat :prefix => false same as :prefix => nil
[#5375 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
Neeraj Singh authored and josevalim committed Sep 1, 2010
1 parent 3df90de commit d1eb9ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Expand Up @@ -113,7 +113,7 @@ def delegate(*methods)
raise ArgumentError, "Can only automatically set the delegation prefix when delegating to a method."
end

prefix = options[:prefix] && "#{options[:prefix] == true ? to : options[:prefix]}_"
prefix = options[:prefix] && "#{options[:prefix] == true ? to : options[:prefix]}_" || ''

file, line = caller.first.split(':', 2)
line = line.to_i
Expand Down
13 changes: 13 additions & 0 deletions activesupport/test/core_ext/module_test.rb
Expand Up @@ -47,6 +47,14 @@ class De
delegate :to_f, :to => :description, :allow_nil => true
end

Developer = Struct.new(:client) do
delegate :name, :to => :client, :prefix => nil
end

Tester = Struct.new(:client) do
delegate :name, :to => :client, :prefix => false
end

class Name
delegate :upcase, :to => :@full_name

Expand Down Expand Up @@ -97,6 +105,11 @@ def test_delegation_custom_prefix
assert_equal invoice.customer_city, "Chicago"
end

def test_delegation_prefix_with_nil_or_false
assert_equal Developer.new(@david).name, "David"
assert_equal Tester.new(@david).name, "David"
end

def test_delegation_prefix_with_instance_variable
assert_raise ArgumentError do
Class.new do
Expand Down

0 comments on commit d1eb9ff

Please sign in to comment.