Permalink
Browse files

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

But `BasicObject#__send__` is still available from the core.
  • Loading branch information...
matz committed Sep 1, 2018
1 parent 593c12a commit b80e0ef7428b613a682da4d2a251c8beb24d6dd2
@@ -34,7 +34,7 @@
}
assert_equal(2) {
a = 10
Kernel.eval 'def f(a); b=a.send(:+, 1); end'
Kernel.eval 'def f(a); b=a+1; end'
f(1)
}
end
@@ -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, "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, "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, "remove_class_variable", mrb_mod_remove_cvar, MRB_ARGS_REQ(1)); /* 15.2.2.4.39 */
@@ -1,3 +1,30 @@
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
o = Object.new
@@ -102,10 +102,7 @@ def bar
assert 'Method#call for regression' do
obj = BasicObject.new
def obj.foo
:ok
end
assert_equal :ok, Kernel.instance_method(:send).bind(obj).call(:foo), "https://github.com/ksss/mruby-method/issues/4"
assert_equal String, Kernel.instance_method(:inspect).bind(obj).call().class, "https://github.com/ksss/mruby-method/issues/4"
end
assert 'Method#call with undefined method' do
View
@@ -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, "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, "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, "__case_eqq", mrb_obj_ceqq, MRB_ARGS_REQ(1)); /* internal */
View
@@ -184,14 +184,14 @@ class Regexp; end
# NODE_UNDEF
assert_nothing_raised do
class << Object.new
undef send
undef inspect
end
end
# NODE_ALIAS
assert_nothing_raised do
class << Object.new
alias send2 send
alias inspect2 inspect
end
end
end
View
@@ -92,20 +92,6 @@ def bg_try(&b)
assert_equal Fixnum, __id__.class
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
def bg_try(&b)
if block_given?
@@ -440,20 +426,6 @@ def test_method; end
assert_false Test4RespondTo.new.respond_to?(:test_method)
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_equal to_s.class, String
end
View
@@ -536,61 +536,61 @@ class << self
#end
# mruby has no visibility control
assert 'Module#prepend visibility' do
bug8005 = '[ruby-core:53106] [Bug #8005]'
c = Class.new do
prepend Module.new {}
def foo() end
protected :foo
end
a = c.new
assert_true a.respond_to?(:foo), bug8005
assert_nothing_raised(bug8005) {a.send :foo}
end
# assert 'Module#prepend visibility' do
# bug8005 = '[ruby-core:53106] [Bug #8005]'
# c = Class.new do
# prepend Module.new {}
# def foo() end
# protected :foo
# end
# a = c.new
# assert_true a.respond_to?(:foo), bug8005
# assert_nothing_raised(bug8005) {a.send :foo}
# end
# mruby has no visibility control
assert 'Module#prepend inherited visibility' do
bug8238 = '[ruby-core:54105] [Bug #8238]'
module Test4PrependVisibilityInherited
class A
def foo() A; end
private :foo
end
class B < A
public :foo
prepend Module.new
end
end
assert_equal(Test4PrependVisibilityInherited::A, Test4PrependVisibilityInherited::B.new.foo, "#{bug8238}")
end
assert 'Module#prepend super in alias' do
skip "super does not currently work in aliased methods"
bug7842 = '[Bug #7842]'
p = labeled_module("P") do
def m; "P"+super; end
end
a = labeled_class("A") do
def m; "A"; end
end
b = labeled_class("B", a) do
def m; "B"+super; end
alias m2 m
prepend p
alias m3 m
end
assert_nothing_raised do
assert_equal("BA", b.new.m2, bug7842)
end
assert_nothing_raised do
assert_equal("PBA", b.new.m3, bug7842)
end
end
# assert 'Module#prepend inherited visibility' do
# bug8238 = '[ruby-core:54105] [Bug #8238]'
# module Test4PrependVisibilityInherited
# class A
# def foo() A; end
# private :foo
# end
# class B < A
# public :foo
# prepend Module.new
# end
# end
# assert_equal(Test4PrependVisibilityInherited::A, Test4PrependVisibilityInherited::B.new.foo, "#{bug8238}")
# end
# assert 'Module#prepend super in alias' do
# skip "super does not currently work in aliased methods"
# bug7842 = '[Bug #7842]'
# p = labeled_module("P") do
# def m; "P"+super; end
# end
# a = labeled_class("A") do
# def m; "A"; end
# end
# b = labeled_class("B", a) do
# def m; "B"+super; end
# alias m2 m
# prepend p
# alias m3 m
# end
# assert_nothing_raised do
# assert_equal("BA", b.new.m2, bug7842)
# end
# assert_nothing_raised do
# assert_equal("PBA", b.new.m3, bug7842)
# end
# end
assert 'Module#prepend each class' do
m = labeled_module("M")

0 comments on commit b80e0ef

Please sign in to comment.