Home > Archive > Ruby > August 2005 > Attributation works in literal class but not in anonymous class?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Attributation works in literal class but not in anonymous class?
|
|
|
|
# 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.
| |
| David A. Black 2005-08-30, 7:02 pm |
| Hi --
On Wed, 31 Aug 2005, Trans wrote:
> def test02
> ac = Class.new { abstract :q }
ac = Class.new { abstract :q } .new
David
--
David A. Black
dblack@wobblini.net
| |
|
|
David A. Black wrote:
> Hi --
>
> On Wed, 31 Aug 2005, Trans wrote:
>
>
> ac = Class.new { abstract :q } .new
>
Doh! Thanks.
T.
|
|
|
|
|