Project

General

Profile

Feature #12495

Make "private" return the arguments again, for chaining

Added by herwinw (Herwin Quarantainenet) about 4 years ago. Updated about 4 years ago.

Status:
Feedback
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:76047]

Description

Ruby 2.1 introduced the feature to make def foo return the symbol, so this could be used by things like private (see #3753):

private def foo() end

You could use the same method to create your own decorators (name borrowed from Python)

def cached(name)
  # Rewrite method to include a cache
  return name
end

private cached def foo() end

Currently, this would work but cached private def foo() would not. private (and all other modifier functions) return the class on which it was called. It would be nice to exterminate those order-dependencies.

The attached patch fixes this. It includes three modes:

No arguments: return nil:

private
  def foo() end

One argument: return the symbol. The would be the most common use case for this example.

private def foo() end
private :bar

Multiple arguments: return an array of the arguments:

private :foo, :bar

Files

ruby_return_symbols_in_private.diff (1.19 KB) ruby_return_symbols_in_private.diff herwinw (Herwin Quarantainenet), 06/16/2016 07:51 AM

Also available in: Atom PDF