Module: British::Initialisable
- Defined in:
- lib/british.rb
Overview
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.
Class Method Summary collapse
-
.included(host_class) ⇒ Object
Public: On British::Initialisable module being included do: 1.
Class Method Details
.included(host_class) ⇒ Object
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
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# 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 |