From: "kernigh (George Koehler)" Date: 2013-03-13T08:32:45+09:00 Subject: [ruby-core:53351] [ruby-trunk - Feature #7998] "def" should return a value (the symbol of the method name) instead of nil Issue #7998 has been updated by kernigh (George Koehler). =begin I have a problem with this feature. module Frog private def self.sound "Ribbit!" end end With this feature, def..end would return :sound, then private :sound would set Frog#sound to private. This is wrong. I defined Frog::sound, not Frog#sound. Surprise! There is no way for private :sound to know that I defined a metamethod, not an instance method; because def..end only returned a Symbol, not the whole definition. With this feature, "private def" only works for instance methods, not for metamethods. =end ---------------------------------------- Feature #7998: "def" should return a value (the symbol of the method name) instead of nil https://bugs.ruby-lang.org/issues/7998#change-37547 Author: pmarreck (Peter Marreck) Status: Open Priority: Normal Assignee: Category: Target version: next minor The C code that implements Ruby method definitions already creates a symbol corresponding to the method name. I propose that the "def... end" block returns this symbol. This would allow the following elegant Ruby code: protected def foo(); end private def bar(); end since "protected" and "private" already take symbol arguments. I estimate that this would be extremely easy to implement while creating extremely minimal existing code impact. I proposed this idea to the #ruby IRC channel on freenode.net and it was received very well, they encouraged me to file this ticket! Thank you for considering. -- http://bugs.ruby-lang.org/