Module: Virtual::ProtocolMethod

Defined in:
lib/virtual/protocol_method.rb

Constant Summary collapse

Error =
Class.new(RuntimeError)

Class Method Summary collapse

Class Method Details

.define(target_class, method_name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/virtual/protocol_method.rb', line 5

def self.define(target_class, method_name)
  method_defined = target_class.method_defined?(method_name, true) ||
    target_class.private_method_defined?(method_name, true)

  if not method_defined
    target_class.send(:define_method, method_name) do |*args|
      raise Error, "Pure virtual (abstract) protocol method #{method_name} of #{self.class.name} must be implemented"
    end
  end
end