Attributation works in literal class but not in anonymous class?
- From: "Trans" <transfire@xxxxxxxxx>
- Date: 30 Aug 2005 11:57:24 -0700
# 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.
.
- Follow-Ups:
- Re: Attributation works in literal class but not in anonymous class?
- From: David A. Black
- Re: Attributation works in literal class but not in anonymous class?
- Prev by Date: SAX-based XPath
- Next by Date: Re: Method behaves differently when called using #send
- Previous by thread: SAX-based XPath
- Next by thread: Re: Attributation works in literal class but not in anonymous class?
- Index(es):
Relevant Pages
|