Move `Kernel#send` to `mruby-metaprog` gem.

But `BasicObject#__send__` is still available from the core.
parent 593c12a5
...@@ -34,7 +34,7 @@ assert('Kernel.eval', '15.3.1.2.3') do ...@@ -34,7 +34,7 @@ assert('Kernel.eval', '15.3.1.2.3') do
} }
assert_equal(2) { assert_equal(2) {
a = 10 a = 10
Kernel.eval 'def f(a); b=a.send(:+, 1); end' Kernel.eval 'def f(a); b=a+1; end'
f(1) f(1)
} }
end end
......
...@@ -680,6 +680,7 @@ mrb_mruby_metaprog_gem_init(mrb_state* mrb) ...@@ -680,6 +680,7 @@ mrb_mruby_metaprog_gem_init(mrb_state* mrb)
mrb_define_method(mrb, krn, "public_methods", mrb_obj_public_methods, MRB_ARGS_OPT(1)); /* 15.3.1.3.38 */ mrb_define_method(mrb, krn, "public_methods", mrb_obj_public_methods, MRB_ARGS_OPT(1)); /* 15.3.1.3.38 */
mrb_define_method(mrb, krn, "singleton_methods", mrb_obj_singleton_methods_m, MRB_ARGS_OPT(1)); /* 15.3.1.3.45 */ mrb_define_method(mrb, krn, "singleton_methods", mrb_obj_singleton_methods_m, MRB_ARGS_OPT(1)); /* 15.3.1.3.45 */
mrb_define_method(mrb, krn, "define_singleton_method", mod_define_singleton_method, MRB_ARGS_ANY()); mrb_define_method(mrb, krn, "define_singleton_method", mod_define_singleton_method, MRB_ARGS_ANY());
mrb_define_method(mrb, krn, "send", mrb_f_send, MRB_ARGS_ANY()); /* 15.3.1.3.44 */
mrb_define_method(mrb, mod, "class_variables", mrb_mod_class_variables, MRB_ARGS_NONE()); /* 15.2.2.4.19 */ mrb_define_method(mrb, mod, "class_variables", mrb_mod_class_variables, MRB_ARGS_NONE()); /* 15.2.2.4.19 */
mrb_define_method(mrb, mod, "remove_class_variable", mrb_mod_remove_cvar, MRB_ARGS_REQ(1)); /* 15.2.2.4.39 */ mrb_define_method(mrb, mod, "remove_class_variable", mrb_mod_remove_cvar, MRB_ARGS_REQ(1)); /* 15.2.2.4.39 */
......
assert('Kernel#__send__', '15.3.1.3.4') do
# test with block
l = __send__(:lambda) do
true
end
assert_true l.call
assert_equal Proc, l.class
# test with argument
assert_true __send__(:respond_to?, :nil?)
# test without argument and without block
assert_equal String, __send__(:to_s).class
end
assert('Kernel#send', '15.3.1.3.44') do
# test with block
l = send(:lambda) do
true
end
assert_true l.call
assert_equal l.class, Proc
# test with argument
assert_true send(:respond_to?, :nil?)
# test without argument and without block
assert_equal send(:to_s).class, String
end
assert('Kernel#instance_variable_defined?', '15.3.1.3.20') do assert('Kernel#instance_variable_defined?', '15.3.1.3.20') do
o = Object.new o = Object.new
......
...@@ -102,10 +102,7 @@ end ...@@ -102,10 +102,7 @@ end
assert 'Method#call for regression' do assert 'Method#call for regression' do
obj = BasicObject.new obj = BasicObject.new
def obj.foo assert_equal String, Kernel.instance_method(:inspect).bind(obj).call().class, "https://github.com/ksss/mruby-method/issues/4"
:ok
end
assert_equal :ok, Kernel.instance_method(:send).bind(obj).call(:foo), "https://github.com/ksss/mruby-method/issues/4"
end end
assert 'Method#call with undefined method' do assert 'Method#call with undefined method' do
......
...@@ -869,7 +869,6 @@ mrb_init_kernel(mrb_state *mrb) ...@@ -869,7 +869,6 @@ mrb_init_kernel(mrb_state *mrb)
mrb_define_method(mrb, krn, "raise", mrb_f_raise, MRB_ARGS_ANY()); /* 15.3.1.3.40 */ mrb_define_method(mrb, krn, "raise", mrb_f_raise, MRB_ARGS_ANY()); /* 15.3.1.3.40 */
mrb_define_method(mrb, krn, "remove_instance_variable", mrb_obj_remove_instance_variable,MRB_ARGS_REQ(1)); /* 15.3.1.3.41 */ mrb_define_method(mrb, krn, "remove_instance_variable", mrb_obj_remove_instance_variable,MRB_ARGS_REQ(1)); /* 15.3.1.3.41 */
mrb_define_method(mrb, krn, "respond_to?", obj_respond_to, MRB_ARGS_ANY()); /* 15.3.1.3.43 */ mrb_define_method(mrb, krn, "respond_to?", obj_respond_to, MRB_ARGS_ANY()); /* 15.3.1.3.43 */
mrb_define_method(mrb, krn, "send", mrb_f_send, MRB_ARGS_ANY()); /* 15.3.1.3.44 */
mrb_define_method(mrb, krn, "to_s", mrb_any_to_s, MRB_ARGS_NONE()); /* 15.3.1.3.46 */ mrb_define_method(mrb, krn, "to_s", mrb_any_to_s, MRB_ARGS_NONE()); /* 15.3.1.3.46 */
mrb_define_method(mrb, krn, "__case_eqq", mrb_obj_ceqq, MRB_ARGS_REQ(1)); /* internal */ mrb_define_method(mrb, krn, "__case_eqq", mrb_obj_ceqq, MRB_ARGS_REQ(1)); /* internal */
......
...@@ -184,14 +184,14 @@ assert('register window of calls (#3783)') do ...@@ -184,14 +184,14 @@ assert('register window of calls (#3783)') do
# NODE_UNDEF # NODE_UNDEF
assert_nothing_raised do assert_nothing_raised do
class << Object.new class << Object.new
undef send undef inspect
end end
end end
# NODE_ALIAS # NODE_ALIAS
assert_nothing_raised do assert_nothing_raised do
class << Object.new class << Object.new
alias send2 send alias inspect2 inspect
end end
end end
end end
...@@ -92,20 +92,6 @@ assert('Kernel#__id__', '15.3.1.3.3') do ...@@ -92,20 +92,6 @@ assert('Kernel#__id__', '15.3.1.3.3') do
assert_equal Fixnum, __id__.class assert_equal Fixnum, __id__.class
end end
assert('Kernel#__send__', '15.3.1.3.4') do
# test with block
l = __send__(:lambda) do
true
end
assert_true l.call
assert_equal Proc, l.class
# test with argument
assert_true __send__(:respond_to?, :nil?)
# test without argument and without block
assert_equal String, __send__(:to_s).class
end
assert('Kernel#block_given?', '15.3.1.3.6') do assert('Kernel#block_given?', '15.3.1.3.6') do
def bg_try(&b) def bg_try(&b)
if block_given? if block_given?
...@@ -440,20 +426,6 @@ assert('Kernel#respond_to?', '15.3.1.3.43') do ...@@ -440,20 +426,6 @@ assert('Kernel#respond_to?', '15.3.1.3.43') do
assert_false Test4RespondTo.new.respond_to?(:test_method) assert_false Test4RespondTo.new.respond_to?(:test_method)
end end
assert('Kernel#send', '15.3.1.3.44') do
# test with block
l = send(:lambda) do
true
end
assert_true l.call
assert_equal l.class, Proc
# test with argument
assert_true send(:respond_to?, :nil?)
# test without argument and without block
assert_equal send(:to_s).class, String
end
assert('Kernel#to_s', '15.3.1.3.46') do assert('Kernel#to_s', '15.3.1.3.46') do
assert_equal to_s.class, String assert_equal to_s.class, String
end end
......
...@@ -536,61 +536,61 @@ end ...@@ -536,61 +536,61 @@ end
#end #end
# mruby has no visibility control # mruby has no visibility control
assert 'Module#prepend visibility' do # assert 'Module#prepend visibility' do
bug8005 = '[ruby-core:53106] [Bug #8005]' # bug8005 = '[ruby-core:53106] [Bug #8005]'
c = Class.new do # c = Class.new do
prepend Module.new {} # prepend Module.new {}
def foo() end # def foo() end
protected :foo # protected :foo
end # end
a = c.new # a = c.new
assert_true a.respond_to?(:foo), bug8005 # assert_true a.respond_to?(:foo), bug8005
assert_nothing_raised(bug8005) {a.send :foo} # assert_nothing_raised(bug8005) {a.send :foo}
end # end
# mruby has no visibility control # mruby has no visibility control
assert 'Module#prepend inherited visibility' do # assert 'Module#prepend inherited visibility' do
bug8238 = '[ruby-core:54105] [Bug #8238]' # bug8238 = '[ruby-core:54105] [Bug #8238]'
module Test4PrependVisibilityInherited # module Test4PrependVisibilityInherited
class A # class A
def foo() A; end # def foo() A; end
private :foo # private :foo
end # end
class B < A # class B < A
public :foo # public :foo
prepend Module.new # prepend Module.new
end # end
end # end
assert_equal(Test4PrependVisibilityInherited::A, Test4PrependVisibilityInherited::B.new.foo, "#{bug8238}") # assert_equal(Test4PrependVisibilityInherited::A, Test4PrependVisibilityInherited::B.new.foo, "#{bug8238}")
end # end
assert 'Module#prepend super in alias' do # assert 'Module#prepend super in alias' do
skip "super does not currently work in aliased methods" # skip "super does not currently work in aliased methods"
bug7842 = '[Bug #7842]' # bug7842 = '[Bug #7842]'
p = labeled_module("P") do # p = labeled_module("P") do
def m; "P"+super; end # def m; "P"+super; end
end # end
a = labeled_class("A") do # a = labeled_class("A") do
def m; "A"; end # def m; "A"; end
end # end
b = labeled_class("B", a) do # b = labeled_class("B", a) do
def m; "B"+super; end # def m; "B"+super; end
alias m2 m # alias m2 m
prepend p # prepend p
alias m3 m # alias m3 m
end # end
assert_nothing_raised do # assert_nothing_raised do
assert_equal("BA", b.new.m2, bug7842) # assert_equal("BA", b.new.m2, bug7842)
end # end
assert_nothing_raised do # assert_nothing_raised do
assert_equal("PBA", b.new.m3, bug7842) # assert_equal("PBA", b.new.m3, bug7842)
end # end
end # end
assert 'Module#prepend each class' do assert 'Module#prepend each class' do
m = labeled_module("M") m = labeled_module("M")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment