Actions
Bug #12478
closedruby2.2.5でオブジェクトに対して def_delegatorを行うとNoMethodError undefined method `method_defined?' が発生する。
Description
-
再現コード
printer = String.new printer.extend SingleForwardable printer.def_delegator "STDOUT", :puts # NoMethodError: undefined method `method_defined?' for "":String
-
原因
-
def_single_delegator
で "method_defined?
"を行っていますが、 -
Moduleクラスをmix-inしていないオブジェクトの場合NoMethodErrorになる。
-
回避方法案
-
Moduleが該当オブジェクトのclassに属していない場合,該当処理をスキップする
```diff --- /usr/local/.rbenv/versions/2.2.5/lib/ruby/2.2.0/forwardable.rb.org 2016-06-10 10:31:09.613979605 +0900 +++ /usr/local/.rbenv/versions/2.2.5/lib/ruby/2.2.0/forwardable.rb 2016-06-10 10:35:06.452506085 +0900 @@ -277,7 +277,7 @@ accessor = accessor.to_s if method_defined?(accessor) || private_method_defined?(accessor) accessor = "#{accessor}()" - end if + end if self.class === Module line_no = __LINE__; str = %{ def #{ali}(*args, &block) ```
-
Updated by nobu (Nobuyoshi Nakada) over 8 years ago
- Description updated (diff)
- Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.1: DONTNEED, 2.2: REQUIRED, 2.3: REQUIRED
Updated by nobu (Nobuyoshi Nakada) over 8 years ago
- Status changed from Open to Closed
Applied in changeset r55366.
forwardable.rb: fix for non-module objects
- lib/forwardable.rb (Forwardable._delegator_method): extract
method generator and deal with non-module objects.
[ruby-dev:49656] [Bug #12478]
Updated by nagachika (Tomoyuki Chikanaga) almost 8 years ago
- Backport changed from 2.1: DONTNEED, 2.2: REQUIRED, 2.3: REQUIRED to 2.1: DONTNEED, 2.2: REQUIRED, 2.3: DONE
ruby_2_3 r57570 merged revision(s) 53383,55366.
Updated by usa (Usaku NAKAMURA) almost 8 years ago
- Backport changed from 2.1: DONTNEED, 2.2: REQUIRED, 2.3: DONE to 2.1: DONTNEED, 2.2: DONE, 2.3: DONE
ruby_2_2 r58085 merged revision(s) 53383,55366.
Actions
Like0
Like0Like0Like0Like0