Attributation works in literal class but not in anonymous class?

T

Trans

# Creates a method that necessitates overridding.
# If it not overridden and called upon a TypeError
# will be raised.
#
# class C
# abstract :a
# end
#
# c = C.new
# c.a #=> Error: undefined abstraction #a
#
class Module
def abstract( *sym )
sym.each { |s|
define_method( s ) { raise TypeError, "undefined abstraction
##{s}" }
}
end
end


require 'test/unit'
#require 'nano/module/abstract'

# fixture

class Aq
abstract :q
end

class TC_Module < Test::Unit::TestCase

# abstract literal

def test01
ac = Aq.new
assert_raises( TypeError ) { ac.q }
end

# abstract anonymous

def test02
ac = Class.new { abstract :q }
assert_raises( TypeError ) { ac.q }
end

end



Loaded suite tc_abstract
Started
..F
Finished in 0.065452 seconds.

1) Failure:
test02(TC_Module) [tc_abstract.rb:22]:
<TypeError> exception expected but was
Class: <NoMethodError>
Message: <"undefined method `q' for #<Class:0xb7cfedf0>">
---Backtrace---
tc_abstract.rb:22:in `test02'
tc_abstract.rb:22:in `assert_raise'
tc_abstract.rb:22:in `test02'
---------------

2 tests, 2 assertions, 1 failures, 0 errors



T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top