Project

General

Profile

Actions

Feature #14778

closed

Make Object#dup accept a block

Added by hkdnet (Ko Sato) almost 6 years ago. Updated almost 6 years ago.

Status:
Feedback
Assignee:
-
Target version:
-
[ruby-core:87197]

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

dup_with_block.diff (296 Bytes) dup_with_block.diff hkdnet (Ko Sato), 05/20/2018 01:14 AM

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #12092: Allow Object#clone to yield cloned object before freezingRejectedActions

Updated by shyouhei (Shyouhei Urabe) almost 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?

Actions #2

Updated by nobu (Nobuyoshi Nakada) almost 6 years ago

  • Related to Feature #12092: Allow Object#clone to yield cloned object before freezing added
Actions

Also available in: Atom PDF

Like0
Like0Like0