Feature #3753

value of def-expr

Added by Usaku NAKAMURA over 3 years ago. Updated 8 months ago.

[ruby-dev:42151]
Status:Closed
Priority:Normal
Assignee:Usaku NAKAMURA
Category:core
Target version:2.1.0

Description

=begin
RubyKaigi見てて思い出したのですが、def式はSymbolを返すようにしませんか?
そうすると、

class Foo
private def foo()
# ...
end
end

などと書けるようになります。

以下パッチ。
Index: vm.c
===================================================================
--- vm.c (リビジョン 29124)
+++ vm.c (作業コピー)
@@ -1893,7 +1893,7 @@ mcoredefinemethod(VALUE self, VALUE c
REWIND
CFP({
vmdefinemethod(GETTHREAD(), cbase, SYM2ID(sym), iseqval, 0, rbvm_cref());
});
- return Qnil;
+ return sym;
}

static VALUE
@@ -1902,7 +1902,7 @@ mcoredefinesingletonmethod(VALUE sel
REWINDCFP({
vm
definemethod(GETTHREAD(), cbase, SYM2ID(sym), iseqval, 1, rbvmcref());
});
- return Qnil;
+ return sym;
}

static VALUE
=end


Related issues

Related to ruby-trunk - Feature #6198: public/protected/private with attr_* Assigned 03/25/2012

Associated revisions

Revision 42337
Added by Usaku NAKAMURA 9 months ago

  • vm.c (mcoredefinemethod, mcoredefinesingleton_method): now
    the value of def-expr is the Symbol of the name of the method, not
    nil.
    ref. [Feature #3753]

  • test/ruby/testsyntax.rb (TestSyntax#testvalueofdef): test for
    above changes.

Revision 42347
Added by Usaku NAKAMURA 9 months ago

  • parse.y (valueexprgen): now NODEDEFN and NODEDEFS are not void value expressions. get rid of wrong warning with -w, and make to pass tests with chkbuild. ref. [Feature #3753]

Revision 42352
Added by Yui NARUSE 9 months ago

Fix test failure to follow r42347 ref #3753

Revision 42551
Added by Usaku NAKAMURA 8 months ago

  • proc.c (rbmoddefine_method): now they return the symbols of the
    defined methods, not the methods/procs themselves.
    [Feature #3753]

  • NEWS: documents about above change and def-expr (see r42337).

  • test/ruby/test_module.rb: tests about above change.

History

#1 Updated by Usaku NAKAMURA over 3 years ago

  • Category set to core
  • Status changed from Open to Assigned
  • Assignee set to Yukihiro Matsumoto

=begin

=end

#2 Updated by Kenta Murata over 3 years ago

=begin
+1
=end

#3 Updated by Yutaka HARA over 1 year ago

  • Description updated (diff)
  • Target version set to next minor

#4 Updated by Usaku NAKAMURA 11 months ago

  • Target version changed from next minor to 2.1.0

RubyKaigiのたびに思い出されるネタなわけですが、そういうわけで再浮上。

#5 Updated by Yukihiro Matsumoto 9 months ago

  • Assignee changed from Yukihiro Matsumoto to Usaku NAKAMURA

We accept this change for 2.1 in the developers' meeting on 2013-07-27. We also think define_method() should return symbols as well.

Matz.

#6 Updated by Usaku NAKAMURA 9 months ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r42337.
Usaku, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • vm.c (mcoredefinemethod, mcoredefinesingleton_method): now
    the value of def-expr is the Symbol of the name of the method, not
    nil.
    ref. [Feature #3753]

  • test/ruby/testsyntax.rb (TestSyntax#testvalueofdef): test for
    above changes.

#7 Updated by Usaku NAKAMURA 9 months ago

  • Status changed from Closed to Assigned
  • % Done changed from 100 to 50

=begin
``definemethod()'' と書かれると迷いが生じるんですが、Module#definemethod が意図されていたということでいいんでしょうか?
で、あれば、こんなもんかと思うんですが、こちらはまだ入れてません。

Index: proc.c
===================================================================
--- proc.c (リビジョン 42336)
+++ proc.c (作業コピー)
@@ -1510,7 +1510,7 @@ rbmoddefinemethod(int argc, VALUE *ar
rb
raise(rb_eTypeError, "wrong argument type (expected Proc/Method)");
}

  • return body;
  • return ID2SYM(id);
    }

    /*
    =end

#8 Updated by Usaku NAKAMURA 9 months ago

  • Status changed from Assigned to Closed
  • % Done changed from 50 to 100

This issue was solved with changeset r42347.
Usaku, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • parse.y (valueexprgen): now NODEDEFN and NODEDEFS are not void value expressions. get rid of wrong warning with -w, and make to pass tests with chkbuild. ref. [Feature #3753]

#9 Updated by Usaku NAKAMURA 9 months ago

  • Status changed from Closed to Assigned
  • % Done changed from 100 to 50

#10 Updated by Yukihiro Matsumoto 8 months ago

Yes, I think Module#define_method should return a symbol as def statement does.

Matz.

#11 Updated by Usaku NAKAMURA 8 months ago

  • Status changed from Assigned to Closed
  • % Done changed from 50 to 100

This issue was solved with changeset r42551.
Usaku, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • proc.c (rbmoddefine_method): now they return the symbols of the
    defined methods, not the methods/procs themselves.
    [Feature #3753]

  • NEWS: documents about above change and def-expr (see r42337).

  • test/ruby/test_module.rb: tests about above change.

Also available in: Atom PDF