Feature #3753

value of def-expr

Added by Usaku NAKAMURA over 4 years ago. Updated over 1 year ago.

[ruby-dev:42151]
Status:Closed
Priority:Normal
Assignee:Usaku NAKAMURA

Description

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

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

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

以下パッチ。
Index: vm.c
===================================================================
--- vm.c (リビジョン 29124)
+++ vm.c (作業コピー)
@@ -1893,7 +1893,7 @@ m_core_define_method(VALUE self, VALUE c
REWIND_CFP({
vm_define_method(GET_THREAD(), cbase, SYM2ID(sym), iseqval, 0, rb_vm_cref());
});
- return Qnil;
+ return sym;
}

static VALUE
@@ -1902,7 +1902,7 @@ m_core_define_singleton_method(VALUE sel
REWIND_CFP({
vm_define_method(GET_THREAD(), cbase, SYM2ID(sym), iseqval, 1, rb_vm_cref());
});
- 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 over 1 year ago

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

  • test/ruby/test_syntax.rb (TestSyntax#test_value_of_def): test for
    above changes.

Revision 42337
Added by Usaku NAKAMURA over 1 year ago

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

  • test/ruby/test_syntax.rb (TestSyntax#test_value_of_def): test for
    above changes.

Revision 42347
Added by Usaku NAKAMURA over 1 year ago

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

Revision 42347
Added by Usaku NAKAMURA over 1 year ago

  • parse.y (value_expr_gen): now NODE_DEFN and NODE_DEFS 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 over 1 year ago

Fix test failure to follow r42347 ref #3753

Revision 42352
Added by Yui NARUSE over 1 year ago

Fix test failure to follow r42347 ref #3753

Revision 42551
Added by Usaku NAKAMURA over 1 year ago

  • proc.c (rb_mod_define_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.

Revision 42551
Added by Usaku NAKAMURA over 1 year ago

  • proc.c (rb_mod_define_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 4 years ago

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

=begin

=end

#2 Updated by Kenta Murata over 4 years ago

=begin
+1
=end

#3 Updated by Yutaka HARA over 2 years ago

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

#4 Updated by Usaku NAKAMURA almost 2 years ago

  • Target version changed from next minor to 2.1.0

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

#5 Updated by Yukihiro Matsumoto over 1 year 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 over 1 year ago

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

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 (m_core_define_method, m_core_define_singleton_method): now
    the value of def-expr is the Symbol of the name of the method, not
    nil.
    ref. [Feature #3753]

  • test/ruby/test_syntax.rb (TestSyntax#test_value_of_def): test for
    above changes.

#7 Updated by Usaku NAKAMURA over 1 year ago

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

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

Index: proc.c
===================================================================
--- proc.c (リビジョン 42336)
+++ proc.c (作業コピー)
@@ -1510,7 +1510,7 @@ rb_mod_define_method(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 over 1 year 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 (value_expr_gen): now NODE_DEFN and NODE_DEFS 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 over 1 year ago

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

#10 Updated by Yukihiro Matsumoto over 1 year ago

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

Matz.

#11 Updated by Usaku NAKAMURA over 1 year 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 (rb_mod_define_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