Exception: NRSER::AbstractMethodError

Inherits:
NotImplementedError
  • Object
show all
Defined in:
lib/nrser/errors.rb

Overview

Extension of Ruby’s NotImplementedError to provide a useful message and convenient constructor for abstract methods.

Examples:


def f
  raise NRSER::AbstractMethodError.new( self, __method__ )

Instance Method Summary collapse

Constructor Details

#initialize(instance, method_name) ⇒ AbstractMethodError

Construct a new ‘AbstractMethodError`.

Parameters:

  • instance (Object)

    Instance that invoked the abstract method.

  • method_name (Symbol | String)

    Name of abstract method.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/nrser/errors.rb', line 27

def initialize instance, method_name
  @instance = instance
  @method_name = method_name
  @method = instance.method @method_name
  
  message = if @method.owner == instance.class
    NRSER.dedent "      Method \#{ @method.owner.name }#\#{ @method_name } is abstract, meaning \n      \#{ @method.owner.name } is an abstract class and the invoking \n      instance \#{ @instance } should NOT have been constructed.\n    END\n  else\n    NRSER.squish <<-END\n      Method \#{ @method.owner.name }#\#{ @method_name } is abstract and \n      has not been implemented in invoking class \#{ @instance.class }.\n      \n      If you *are* developing the invoking class \#{ @instance.class } it\n      (or a parent class between it and \#{ @method.owner.name }) must \n      implement #\#{ @method_name }.\n      \n      If you *are not* developing \#{ @instance.class } it should be treated\n      as an abstract base class and should NOT be constructed. You need to\n      find a subclass of \#{ @instance.class } to instantiate or write \n      your own.\n    END\n  end\n  \n  super message\nend\n"