Feature #3753
closedvalue of def-expr
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
Updated by usa (Usaku NAKAMURA) over 14 years ago
- Category set to core
- Status changed from Open to Assigned
- Assignee set to matz (Yukihiro Matsumoto)
=begin
=end
Updated by yhara (Yutaka HARA) about 12 years ago
- Description updated (diff)
- Target version set to 2.6
Updated by usa (Usaku NAKAMURA) over 11 years ago
- Target version changed from 2.6 to 2.1.0
RubyKaigiのたびに思い出されるネタなわけですが、そういうわけで再浮上。
Updated by matz (Yukihiro Matsumoto) over 11 years ago
- Assignee changed from matz (Yukihiro Matsumoto) to usa (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.
Updated by usa (Usaku NAKAMURA) over 11 years 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 (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. [ruby-dev:42151] [Feature #3753] -
test/ruby/test_syntax.rb (TestSyntax#test_value_of_def): test for
above changes.
Updated by usa (Usaku NAKAMURA) over 11 years 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
Updated by usa (Usaku NAKAMURA) over 11 years 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]
Updated by usa (Usaku NAKAMURA) over 11 years ago
- Status changed from Closed to Assigned
- % Done changed from 100 to 50
Updated by matz (Yukihiro Matsumoto) over 11 years ago
Yes, I think Module#define_method should return a symbol as def statement does.
Matz.
Updated by usa (Usaku NAKAMURA) over 11 years 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.
[ruby-dev:42151] [Feature #3753] -
NEWS: documents about above change and def-expr (see r42337).
-
test/ruby/test_module.rb: tests about above change.