Skip to content

Commit

Permalink
JSI::Util::Virtual
Browse files Browse the repository at this point in the history
  • Loading branch information
notEthan committed Dec 8, 2020
1 parent effcd07 commit 80032f5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/jsi/util.rb
Expand Up @@ -102,6 +102,25 @@ def jsi_clear_memo(key, *args)
end
end
end

module Virtual
class InstantiationError < StandardError
end

# this virtual class is not intended to be instantiated except by its subclasses, which override #initialize
def initialize
# :nocov:
raise(InstantiationError, "cannot instantiate virtual class #{self.class}")
# :nocov:
end

# virtual_method is used to indicate that the method calling it must be implemented on the (non-virtual) subclass
def virtual_method
# :nocov:
raise(Bug, "class #{self.class} must implement #{caller_locations.first.label}")
# :nocov:
end
end
end
public
extend Util
Expand Down

0 comments on commit 80032f5

Please sign in to comment.