Feature #4978

forwardable: support for 'delegate :method => :accessor'

Added by Benoit Daloze almost 3 years ago. Updated over 1 year ago.

[ruby-core:37804]
Status:Assigned
Priority:Normal
Assignee:Keiju Ishitsuka
Category:lib
Target version:next minor

Description

Hello,

A few months ago, I met a bug with lib/forwardable.rb:

delegate :method => :accessor

would not work, although mentioned in the documentation.

Keiju solved this at r31507, being faster than me :)

However, I would still like to propose my solution.

#instancedelegate and #singledelegate both accept
a Symbol-Symbol pair (:method => :accessor)
and a Array-Symbol pair ([:method1, :method2] => :accessor).

The current code looks like:

methods = [methods] unless methods.respondto?(:each)
methods.each{ |method|
def
instance_delegator(accessor, method)
}

I propose:

Array(methods).each{ |method|
definstancedelegator(accessor, method)
}

I believe this is a good use for Kernel#Array, and it does not depend on #each being defined on Symbol/String.

While I am at it, I would like to advise to not use the fact String#each for a single line String used to yield the whole String.
This is likely not what #each is intended for, and broke with 1.9, which undefined String#each.

I began to write a few tests for forwardable, is it better to add them in test/ or RubySpec ?

0001-lib-forwardable-Forwardable-instance_delegate-Single.patch Magnifier (1.16 KB) Benoit Daloze, 07/06/2011 01:39 AM

History

#1 Updated by Motohiro KOSAKI almost 3 years ago

  • Status changed from Open to Assigned
  • Assignee set to Keiju Ishitsuka

I believe this is new feature, not bug. However if Keiju will accept and commit it before preview1, I have no objection.
Otherwise I'll change it 'Feature' for 1.9.4. I'm sorry this is very short time limit, but the proposal seems too late.

Thanks.

#2 Updated by Benoit Daloze almost 3 years ago

Motohiro KOSAKI wrote:

I believe this is new feature, not bug. However if Keiju will accept and commit it before preview1, I have no objection.
Otherwise I'll change it 'Feature' for 1.9.4. I'm sorry this is very short time limit, but the proposal seems too late.

Thanks.

My mistake, I meant it as a feature.
The delay is fine, this is not urgent at all (but I'd like feedback from Keiji one day).
Thanks for looking in this issue.

#3 Updated by Motohiro KOSAKI almost 3 years ago

  • Tracker changed from Bug to Feature

#4 Updated by Motohiro KOSAKI over 2 years ago

  • Target version changed from 1.9.3 to 2.0.0

#5 Updated by Koichi Sasada over 1 year ago

  • Target version changed from 2.0.0 to next minor

I changed target to next minor because no discussion.

Also available in: Atom PDF