Sha256: cf4dff9087f3cc2fd5a3f5823937bda20c1515e45d4836b2d79377ff047c78bd
Contents?: true
Size: 920 Bytes
Versions: 10
Compression:
Stored size: 920 Bytes
Contents
# TITLE: # # Abstract method. # # SUMMARY: # # Create an abstrct method. If it is not overriden it will raise # an exception when called. # # AUTHORS: # # - Thomas Sawyer # class Module # Creates a method that requires to be 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 # def abstract( *sym ) sym.each { |s| define_method( s ) { raise TypeError, "undefined abstraction ##{s}" } } end end =begin test require 'test/unit' class TestAttrTester < Test::Unit::TestCase class Aq abstract :q end def test_abstract_01 ac = Aq.new assert_raises( TypeError ) { ac.q } end def test_abstract_02 ac = Class.new { abstract :q }.new assert_raises( TypeError ) { ac.q } end end =end
Version data entries
10 entries across 10 versions & 1 rubygems