Actions
Feature #14778
closedMake Object#dup accept a block
Status:
Feedback
Assignee:
-
Target version:
-
Description
I'd like to use Object#dup
with a block, which is equivalent to dup.tap
.
An example for dup.tap
is here.
require 'uri'
module MyUri
class << self
def foo_uri
base_uri.dup.tap { |e| e.path = '/foo' }
end
private
def base_uri
@base_uri ||= URI.parse('http://example.com')
end
end
end
With this patch, we can write base_uri.dup { |e| e.path = '/foo' }
and it's simpler.
Files
Updated by shyouhei (Shyouhei Urabe) over 6 years ago
- Status changed from Open to Feedback
Not an immediate NG, but curious why we should do this in core, instead of your gem?
Would you mind telling us the reason this should be enabled for all the ruby users around the world?
Updated by nobu (Nobuyoshi Nakada) over 6 years ago
- Related to Feature #12092: Allow Object#clone to yield cloned object before freezing added
Actions
Like0
Like0Like0