assert('The alias statement', '13.3.6 a) 4)') do
def alias_test_method_original; true; end
alias alias_test_method_a alias_test_method_original
alias :alias_test_method_b :alias_test_method_original
assert_true(alias_test_method_original)
assert_true(alias_test_method_a)
assert_true(alias_test_method_b)
end
assert('The alias statement (overwrite original)', '13.3.6 a) 4)') do
def alias_test_method_original; true; end
alias alias_test_method_a alias_test_method_original
alias :alias_test_method_b :alias_test_method_original
assert_true(alias_test_method_original)
def alias_test_method_original; false; end
assert_false(alias_test_method_original)
assert_true(alias_test_method_a)
assert_true(alias_test_method_b)
end
assert('The alias statement', '13.3.6 a) 5)') do
assert_raise(NameError) do
alias new_name_a non_existing_method
end
assert_raise(NameError) do
alias :new_name_b :non_existing_method
end
end
assert('The undef statement', '13.3.7 a) 4)') do
def existing_method_a; true; end
def existing_method_b; true; end
def existing_method_c; true; end
def existing_method_d; true; end
def existing_method_e; true; end
def existing_method_f; true; end
assert_true(existing_method_a, 'Method should be defined')
assert_true(existing_method_b, 'Method should be defined')
assert_true(existing_method_c, 'Method should be defined')
assert_true(existing_method_d, 'Method should be defined')
assert_true(existing_method_e, 'Method should be defined')
assert_true(existing_method_f, 'Method should be defined')
undef existing_method_a
assert_raise(NoMethodError) do
existing_method_a
end
undef :existing_method_b
assert_raise(NoMethodError) do
existing_method_b
end
undef existing_method_c, existing_method_d
assert_raise(NoMethodError) do
existing_method_c
end
assert_raise(NoMethodError) do
existing_method_d
end
undef :existing_method_e, :existing_method_f
assert_raise(NoMethodError) do
existing_method_e
end
assert_raise(NoMethodError) do
existing_method_f
end
end
assert('The undef statement (method undefined)', '13.3.7 a) 5)') do
assert_raise(NameError) do
undef non_existing_method
end
assert_raise(NameError) do
undef :non_existing_method
end
end
assert('method_added hook') do
c = Class.new do
def self.name; @name; end
def self.method_added(name) @name = name; end
def foo; end
end
assert_equal(:foo, c.name)
c.define_method(:bar){}
assert_equal(:bar, c.name)
end
assert('singleton_method_added hook') do
a = Object.new
def a.name; @name; end
def a.singleton_method_added(name) @name = name; end
def a.foo; end
assert_equal(:foo, a.name)
class <<a
def bar; end
end
assert_equal(:bar, a.name)
end