Project

General

Profile

Bug #17560

Does `Module#ruby2_keywords` return `nil` or `self`?

Added by nobu (Nobuyoshi Nakada) about 2 months ago. Updated 19 days ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:102158]

Description

The RDoc says that it returns self:

ruby2_keywords(method_name, ...)    -> self

This seems consistent with other methods which accept method names, e.g., public, private, etc.

But it actually returns nil, and TestKeywordArguments#test_ruby2_keywords also has 2 assert_nils.

Which is intentional?

patch to fix code as the doc

Updated by nobu (Nobuyoshi Nakada) about 2 months ago

  • Assignee changed from jeremyevans0 (Jeremy Evans) to mame (Yusuke Endoh)
  • Description updated (diff)

Updated by mame (Yusuke Endoh) about 2 months ago

  • Assignee changed from mame (Yusuke Endoh) to jeremyevans0 (Jeremy Evans)

I think either is fine. This is a weak opinion, but it looks safer to me not to change the actual return value. jeremyevans0 (Jeremy Evans) Do you have an opinion?

Updated by jeremyevans0 (Jeremy Evans) about 2 months ago

My intention was to return nil, so this is a documentation bug.

Updated by zverok (Victor Shepelev) about 2 months ago

Shouldn't it actually return method's name?.. For things like

private ruby2_keywords def my_method
  # ....
end

?..

Updated by jeremyevans0 (Jeremy Evans) about 2 months ago

zverok (Victor Shepelev) wrote in #note-4:

Shouldn't it actually return method's name?.. For things like

private ruby2_keywords def my_method
  # ....
end

?..

That was not my intention, though I don't object to it if someone else wants to make that change. Note that it would have to return an array of symbols, not a single symbol, since ruby2_keywords accepts arbitrary arguments. Also, it raises the question whether ruby2_keywords should include a method symbol if it doesn't mark the method and issues a warning instead.

Updated by Eregon (Benoit Daloze) about 2 months ago

Since ruby2_keywords is often used conditionally, I think there is little value for it to return Symbols:
https://github.com/rails/rails/blob/291a3d2ef29a3842d1156ada7526f4ee60dd2b59/actionpack/lib/action_dispatch/middleware/stack.rb#L94

Also private ruby2_keywords def foo seems very long and hard to read.

#7

Updated by jeremyevans (Jeremy Evans) 25 days ago

  • Status changed from Assigned to Closed

Applied in changeset git|49d3830f44031174ad450a0ea1cdcdf0eabf9d0e.


Fix documentation for Module#ruby2_keywords

It returns nil, not self.

Fixes [Bug #17560]

Updated by nagachika (Tomoyuki Chikanaga) 24 days ago

  • Backport changed from 2.5: DONTNEED, 2.6: DONTNEED, 2.7: REQUIRED, 3.0: REQUIRED to 2.5: DONTNEED, 2.6: DONTNEED, 2.7: DONE, 3.0: REQUIRED

ruby_2_7 ea222b05571741f36b59f615c2e83b3adafbd398 merged revision(s) 49d3830f44031174ad450a0ea1cdcdf0eabf9d0e.

Updated by naruse (Yui NARUSE) 19 days ago

  • Backport changed from 2.5: DONTNEED, 2.6: DONTNEED, 2.7: DONE, 3.0: REQUIRED to 2.5: DONTNEED, 2.6: DONTNEED, 2.7: DONE, 3.0: DONE

ruby_3_0 38f9c832e812f96fd06ca73688ff2baa528c119c merged revision(s) 49d3830f44031174ad450a0ea1cdcdf0eabf9d0e.

Also available in: Atom PDF