Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Undefine SimpleDelegator#open due to private method interference #449

Closed
wants to merge 2 commits into from

1 participant

Jon Rowe
Jon Rowe

Including ::Kernel.dup brings across the #open method into
SimpleDelegator with undesirable consequences.

e.g.

class A
  def open
  end
end

SimpleDelegator.new(A.new).open
# => nil

SimpleDelegator.new(A.new).send :open
# ArgumentError: wrong number of arguments (0 for 1..3)

/cc @nobu this shows the real problem
JonRowe added some commits
Jon Rowe JonRowe Undefine SimpleDelegator#open
Including `::Kernel.dup` brings across the #open method into
SimpleDelegator with undesirable consequences.

e.g.

```Ruby
  class A
  end
  SimpleDelegator.new(A.new).open
  # => NoMethodError: private method `open' called for #<A:0x007fca1aa1fbd0>
```
432afe9
Jon Rowe JonRowe spec showing private method interference from kernel 2778eaa
Nobuyoshi Nakada nobu closed this pull request from a commit
Nobuyoshi Nakada nobu delegate.rb: get rid of global function interference
* lib/delegate.rb (Delegator#send): override to get rid of global function interference.
  [Fixes GH-449]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
ca57399
Nobuyoshi Nakada nobu closed this in ca57399
Jon Rowe JonRowe deleted the branch
Masaki Matsushita Glasssaga referenced this pull request from a commit in Glasssaga/ruby
Nobuyoshi Nakada nobu delegate.rb: get rid of global function interference
* lib/delegate.rb (Delegator#send): override to get rid of global function interference.
  [Fixes GH-449]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
cd3409d
Nobuyoshi Nakada nobu referenced this pull request from a commit
Nobuyoshi Nakada nobu delegate.rb: try private methods after the target
* lib/delegate.rb (Delegator#method_missing): try private methods defined in
  Kernel after the target.  [Fixes GH-449]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
594eec5
Masaki Matsushita Glasssaga referenced this pull request from a commit in Glasssaga/ruby
Nobuyoshi Nakada nobu delegate.rb: try private methods after the target
* lib/delegate.rb (Delegator#method_missing): try private methods defined in
  Kernel after the target.  [Fixes GH-449]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
07b5e78
Aaron Patterson tenderlove referenced this pull request from a commit in tenderlove/ruby
Nobuyoshi Nakada nobu delegate.rb: get rid of global function interference
* lib/delegate.rb (Delegator#send): override to get rid of global function interference.
  [Fixes GH-449]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
39a9a01
Aaron Patterson tenderlove referenced this pull request from a commit in tenderlove/ruby
Nobuyoshi Nakada nobu delegate.rb: try private methods after the target
* lib/delegate.rb (Delegator#method_missing): try private methods defined in
  Kernel after the target.  [Fixes GH-449]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
37344e7
Evan Phoenix evanphx referenced this pull request from a commit
unak unak merge revision(s) 43682,43727,43752,43759: [Backport #9560]
	* lib/delegate.rb (Delegator#send): override to get rid of global function interference.
	  [Fixes GH-449]

	* lib/delegate.rb (Delegator#send): separate from method_missing so
	  that super calls proper method.

	* lib/delegate.rb (Delegator#method_missing): try private methods defined in
	  Kernel after the target.  [Fixes GH-449]

	* lib/delegate.rb (SimpleDelegator#__getobj__): target object must be set.

	* lib/delegate.rb (DelegateClass#__getobj__): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@45747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
292d506
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 14, 2013
  1. Jon Rowe

    Undefine SimpleDelegator#open

    JonRowe authored
    Including `::Kernel.dup` brings across the #open method into
    SimpleDelegator with undesirable consequences.
    
    e.g.
    
    ```Ruby
      class A
      end
      SimpleDelegator.new(A.new).open
      # => NoMethodError: private method `open' called for #<A:0x007fca1aa1fbd0>
    ```
  2. Jon Rowe
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 2 deletions.
  1. +1 −1  lib/delegate.rb
  2. +13 −1 test/test_delegate.rb
2  lib/delegate.rb
View
@@ -43,7 +43,7 @@
class Delegator < BasicObject
kernel = ::Kernel.dup
kernel.class_eval do
- [:to_s,:inspect,:=~,:!~,:===,:<=>,:eql?,:hash].each do |m|
+ [:to_s,:inspect,:=~,:!~,:===,:<=>,:eql?,:hash,:open].each do |m|
undef_method m
end
end
14 test/test_delegate.rb
View
@@ -1,5 +1,5 @@
require 'test/unit'
-require 'delegate'
+require './lib/delegate'
class TestDelegateClass < Test::Unit::TestCase
module M
@@ -48,6 +48,9 @@ class Foo
def m
:m
end
+ def open
+ :opened
+ end
def delegate_test_m
:m
end
@@ -133,4 +136,13 @@ def test_private_method
assert_raise(NoMethodError, '[ruby-dev:40314]#4') {d.delegate_test_private}
assert_raise(NoMethodError, '[ruby-dev:40314]#5') {d.send(:delegate_test_private)}
end
+
+ def test_private_methods_from_kernel_dont_interfer
+ foo = Foo.new
+ d = SimpleDelegator.new(foo)
+ assert_equal(:opened, foo.open)
+ assert_equal(:opened, d.open)
+ assert_equal(:opened, foo.send(:open))
+ assert_equal(:opened, d.send(:open))
+ end
end
Something went wrong with that request. Please try again.