Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 

virtual

Virtual method declaration.

Summary

A virtual method is a method which is inheritable and overridable. Since all methods in ruby are virtual, syntax is not required to provide this capability.

When developing framework style code, it is often required to override or implement a specific method in order to satisfy a contract. The purpose of this library is to provide a way for a developer of framework code to convey that intent.

The virtual library adds two macros to a class:

  • virtual
  • pure_virtual

virtual is an indication that a method may be overridden. pure_virtual is an indication that a method must be overridden in a subclass (if it is not, an error will be raised when called).

The pure_virtual macro is also aliased to abstract.

Activation

The virtual and pure_virtual macros can be added to all classes with:

require 'virtual'
Virtual.activate

To avoid modifying the Object class, include the Virtual module directly in a class rather than activating it globally with Virtual.activate.

Example

class Something
  virtual :my_optional_method
  pure_virtual :my_required_method
end

If the virtual library is not activated, the module can be included in the class:

class Something
  include Virtual

  virtual :my_optional_method
  pure_virtual :my_required_method
end

The pure_virtual macro is also aliased to abstract:

class Something
  include Virtual

  abstract :my_required_method
end

License

The virtual library is released under the MIT License.

About

Virtual method declaration

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •