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 o.instance_variable_set(:@a, 1) assert_true o.instance_variable_defined?("@a") assert_false o.instance_variable_defined?("@b") assert_true o.instance_variable_defined?("@a"[0,2]) assert_true o.instance_variable_defined?("@abc"[0,2]) assert_raise(NameError) { o.instance_variable_defined?("@0") } end assert('Kernel#instance_variable_get', '15.3.1.3.21') do o = Class.new { attr_accessor :foo, :bar }.new o.foo = "one" o.bar = 2 assert_equal("one", o.instance_variable_get(:@foo)) assert_equal(2, o.instance_variable_get("@bar")) assert_equal(nil, o.instance_variable_get(:@baz)) %w[foo @1].each do |n| assert_raise(NameError) { o.instance_variable_get(n) } end end assert('Kernel#instance_variable_set', '15.3.1.3.22') do o = Class.new { attr_reader :foo, :_bar }.new assert_equal("one", o.instance_variable_set(:@foo, "one")) assert_equal("one", o.foo) assert_equal(2, o.instance_variable_set("@_bar", 2)) assert_equal(2, o._bar) %w[@6 @% @@a @ a].each do |n| assert_raise(NameError) { o.instance_variable_set(n, 1) } end end assert('Kernel#instance_variables', '15.3.1.3.23') do o = Object.new o.instance_eval do @a = 11 @b = 12 end ivars = o.instance_variables assert_equal Array, ivars.class, assert_equal(2, ivars.size) assert_true ivars.include?(:@a) assert_true ivars.include?(:@b) end assert('Kernel#methods', '15.3.1.3.31') do assert_equal Array, methods.class end assert('Kernel#private_methods', '15.3.1.3.36') do assert_equal Array, private_methods.class end assert('Kernel#protected_methods', '15.3.1.3.37') do assert_equal Array, protected_methods.class end assert('Kernel#public_methods', '15.3.1.3.38') do assert_equal Array, public_methods.class class Foo def foo end end assert_equal [:foo], Foo.new.public_methods(false) end assert('Kernel#singleton_methods', '15.3.1.3.45') do assert_equal singleton_methods.class, Array end assert('Kernel.local_variables', '15.3.1.2.7') do a, b = 0, 1 a += b vars = Kernel.local_variables.sort assert_equal [:a, :b, :vars], vars assert_equal [:a, :b, :c, :vars], Proc.new { |a, b| c = 2 # Kernel#local_variables: 15.3.1.3.28 local_variables.sort }.call(-1, -2) end assert('Kernel#define_singleton_method') do o = Object.new ret = o.define_singleton_method(:test_method) do :singleton_method_ok end assert_equal :test_method, ret assert_equal :singleton_method_ok, o.test_method end def labeled_module(name, &block) Module.new do (class <