Bug #17560
closedDoes `Module#ruby2_keywords` return `nil` or `self`?
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_nil
s.
Which is intentional?
Updated by nobu (Nobuyoshi Nakada) about 4 years ago
- Description updated (diff)
- Assignee changed from jeremyevans0 (Jeremy Evans) to mame (Yusuke Endoh)
Updated by mame (Yusuke Endoh) about 4 years 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 4 years ago
My intention was to return nil
, so this is a documentation bug.
Updated by zverok (Victor Shepelev) about 4 years 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 4 years 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 4 years 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.
Updated by jeremyevans (Jeremy Evans) about 4 years 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) about 4 years 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) about 4 years 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.