module British::Initialisable

Public: Submodule to be included in your own classes to use `initialise` and allow American methods to be called from outside

Warning: as far as `initialize` called automatically by a `new` method there is no sense to use it for third party classes. Use `include British` instead.

Public Class Methods

included(host_class) click to toggle source

Public: On British::Initialisable 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`)
4. Patch a class with British magic `method_missing`
5. Add aliases for `is_a?`

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

# File lib/british.rb, line 125
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

  host_class.extend ClassMethods
  host_class.class_overwrite_method_missing

  alias_method(:is_an?, :is_a?)
  alias_method(:an?, :is_an?)
end