class NRSER::AbstractMethodError
Extension of Ruby's {NotImplementedError} to provide a useful message and convenient constructor for abstract methods.
This is a {NRSER::NicerError}.
@example
def f raise NRSER::AbstractMethodError.new( self, __method__ )
Attributes
instance[R]
TODO document `instance` attribute.
@return [attr_type]
method_instance[R]
TODO document `method_instance` attribute.
@return [Method]
method_name[R]
The abstract method's name that was called¹.
> ¹ I mean, that's what it should be, it's really just what was passed > as the `method_name:` keyword to {#initialize}.
@return [Symbol]
Public Class Methods
new(instance, method_name)
click to toggle source
Construct a new `AbstractMethodError`.
@param [Object] instance
Instance that invoked the abstract method.
@param [Symbol | String] method_name
Name of abstract method.
Calls superclass method
NRSER::NicerError::new
# File lib/nrser/errors/abstract_method_error.rb, line 65 def initialize instance, method_name @instance = instance @method_name = method_name @method_instance = instance.method @method_name super() end
Public Instance Methods
context()
click to toggle source
# File lib/nrser/errors/abstract_method_error.rb, line 113 def context { instance: instance, method_name: method_name, } end
default_message()
click to toggle source
# File lib/nrser/errors/abstract_method_error.rb, line 121 def default_message "Method ##{ method_name.to_s } is abstract" end
details()
click to toggle source
# File lib/nrser/errors/abstract_method_error.rb, line 126 def details @details ||= if method_owner == instance.class <<~END Method #{ method_full_name } is abstract, meaning #{ method_owner_name } is an abstract class and the invoking instance #{ instance } should NOT have been constructed. END else <<~END Method #{ method_full_name } is abstract and has not been implemented in invoking class #{ instance.class }. If you *are* developing the invoking class #{ instance.class } it (or a parent class between it and #{ method_owner_name }) must implement ##{ method_name.to_s }. If you *are not* developing #{ instance.class } it should be treated as an abstract base class and should NOT be constructed. You need to find a subclass of #{ instance.class } to instantiate or write your own. END end end
method_full_name()
click to toggle source
# File lib/nrser/errors/abstract_method_error.rb, line 106 def method_full_name lazy_var :@method_full_name do "#{ method_owner_name }##{ method_name.to_s }" end end
method_owner()
click to toggle source
# File lib/nrser/errors/abstract_method_error.rb, line 88 def method_owner lazy_var :@method_owner do method_instance && method_instance.owner end end
method_owner_name()
click to toggle source
# File lib/nrser/errors/abstract_method_error.rb, line 95 def method_owner_name lazy_var :@method_owner_name do if method_owner method_owner.safe_name else '???' end end end