Project

General

Profile

Actions

Feature #8896

open

#tap with missing block

Added by prijutme4ty (Ilya Vorontsov) about 11 years ago. Updated almost 3 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:57134]

Description

In case when no block provided to tap, it fails. So if you want method which can be called with or without block - you can't do it like this:

def self.create(args={}, &block)
new.set_attributes(args).tap(&block)
end

but should use block_defined? to prevent #tap's failure.

I suggest to make tap with no block given just to return self and raise no errors.

Updated by Anonymous about 11 years ago

I would like to see tap return an Enumerator if a block is not passed.

Updated by prijutme4ty (Ilya Vorontsov) about 11 years ago

I would like to see tap return an Enumerator if a block is not passed.
Can you explain your suggestion a bit more? I can't imagine realization and use-case yet.

Updated by fuadksd (Fuad Saud) about 11 years ago

#tap without a block returning self makes sense

--
Fuad Saud
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

On Wednesday, September 11, 2013 at 1:54 PM, prijutme4ty (Ilya Vorontsov) wrote:

Issue #8896 has been updated by prijutme4ty (Ilya Vorontsov).

I would like to see tap return an Enumerator if a block is not passed.
Can you explain your suggestion a bit more? I can't imagine realization and use-case yet.


Feature #8896: #tap with missing block
https://bugs.ruby-lang.org/issues/8896#change-41756

Author: prijutme4ty (Ilya Vorontsov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:

In case when no block provided to tap, it fails. So if you want method which can be called with or without block - you can't do it like this:

def self.create(args={}, &block)
new.set_attributes(args).tap(&block)
end

but should use block_defined? to prevent #tap's failure.

I suggest to make tap with no block given just to return self and raise no errors.

--
http://bugs.ruby-lang.org/

Updated by shuber (Sean Huber) almost 6 years ago

Kernel#tap related: Allow Kernel#tap to be invoked with arguments like Kernel#send - https://bugs.ruby-lang.org/issues/15419

If the LocalJumpError breaking change from this ticket is not an issue then it'd be pretty easy to add logic to that PR^ supporting it.

Actions #5

Updated by hsbt (Hiroshi SHIBATA) almost 3 years ago

  • Project changed from 14 to Ruby master
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0