зеркало из https://github.com/github/ruby.git
vm_args.c: allow refinements in Symbol proc
* vm_args.c (refine_sym_proc_call): search and call method with refinements. * vm_args.c (vm_caller_setup_arg_block): enable refinements when enabled in the caller. [Feature #9451] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
69692d4851
Коммит
35a2939019
|
@ -1,3 +1,11 @@
|
|||
Sat Oct 15 14:17:05 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* vm_args.c (refine_sym_proc_call): search and call method with
|
||||
refinements.
|
||||
|
||||
* vm_args.c (vm_caller_setup_arg_block): enable refinements when
|
||||
enabled in the caller. [Feature #9451]
|
||||
|
||||
Sat Oct 15 00:54:01 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* process.c (proc_exec_cmd): use UTF-8 version aspawn.
|
||||
|
|
2
NEWS
2
NEWS
|
@ -17,6 +17,8 @@ with all sufficient information, see the ChangeLog file or Redmine
|
|||
* Multiple assignment in conditional expression is now allowed.
|
||||
[Feature #10617]
|
||||
|
||||
* Refinments is enabled at method by Symbol#to_proc. [Feature #9451]
|
||||
|
||||
=== Core classes updates (outstanding ones only)
|
||||
|
||||
* Array
|
||||
|
|
|
@ -435,4 +435,16 @@ class TestSymbol < Test::Unit::TestCase
|
|||
assert_equal str, str.to_sym.to_s
|
||||
assert_not_predicate(str, :frozen?, bug11721)
|
||||
end
|
||||
|
||||
module WithRefinements
|
||||
using Module.new {refine(Integer) {alias inc succ}}
|
||||
def mapinc(a)
|
||||
a.map(&:inc)
|
||||
end
|
||||
end
|
||||
|
||||
def test_proc_with_refinements
|
||||
obj = Object.new.extend WithRefinements
|
||||
assert_equal [*1..3], obj.mapinc(0..2)
|
||||
end
|
||||
end
|
||||
|
|
24
vm_args.c
24
vm_args.c
|
@ -794,6 +794,26 @@ vm_to_proc(VALUE proc)
|
|||
}
|
||||
}
|
||||
|
||||
static VALUE
|
||||
refine_sym_proc_call(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
|
||||
{
|
||||
VALUE obj;
|
||||
ID mid;
|
||||
const rb_callable_method_entry_t *me;
|
||||
|
||||
if (argc-- < 1) {
|
||||
rb_raise(rb_eArgError, "no receiver given");
|
||||
}
|
||||
obj = *argv++;
|
||||
mid = SYM2ID(callback_arg);
|
||||
me = rb_callable_method_entry_with_refinements(CLASS_OF(obj), mid);
|
||||
if (!me) {
|
||||
/* fallback to funcall (e.g. method_missing) */
|
||||
return rb_funcall_with_block(obj, mid, argc, argv, blockarg);
|
||||
}
|
||||
return vm_call0(GET_THREAD(), obj, mid, argc, argv, me);
|
||||
}
|
||||
|
||||
static void
|
||||
vm_caller_setup_arg_block(const rb_thread_t *th, rb_control_frame_t *reg_cfp,
|
||||
struct rb_calling_info *calling, const struct rb_call_info *ci, rb_iseq_t *blockiseq, const int is_super)
|
||||
|
@ -806,6 +826,10 @@ vm_caller_setup_arg_block(const rb_thread_t *th, rb_control_frame_t *reg_cfp,
|
|||
}
|
||||
else {
|
||||
if (SYMBOL_P(block_code) && rb_method_basic_definition_p(rb_cSymbol, idTo_proc)) {
|
||||
const rb_cref_t *cref = vm_env_cref(reg_cfp->ep);
|
||||
if (cref && !NIL_P(cref->refinements)) {
|
||||
block_code = rb_func_proc_new(refine_sym_proc_call, block_code);
|
||||
}
|
||||
calling->block_handler = block_code;
|
||||
}
|
||||
else {
|
||||
|
|
Загрузка…
Ссылка в новой задаче