Module: British::Initialisable

Defined in:
lib/british.rb

Overview

Public: Submodule to be included in your own classes to use initialise

As far as initialize called automatically by a new method there is no sense to use it for third party classes.

Class Method Summary collapse

Class Method Details

.included(host_class) ⇒ Object

Public: On module being included do:

1. Check if it's a global include
2. Add and alias of the parent's `initialize` (for `super` calls)
3. Create your own initialize method (to be auto-called by the `new`)

Warning

By including this module you redefine your initialiZe method.
Use initialiSe method instead of the original, but not both!

Example:

include British::Initialisable

Returns nothing



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/british.rb', line 89

def self.included(host_class)
  unless host_class == Object
    # alias parent's initialise method
    host_class.superclass.class_eval do
      alias_method :initialise, :initialize
    end

    # suppress 'method redefined; discarding old initialize' warning
    # https://goo.gl/PSzrbF ¯\_(ツ)_/¯
    verbose = $VERBOSE
    $VERBOSE = nil

    # Once again: since we use this Initialisable module in our classes
    # ONLY, and create our own initialiSe method, we can't break anything
    # by redefining initialiZe
    define_method :initialize do |*args|
      initialise(*args)
    end

    $VERBOSE = verbose
  end
end