Module: Kinda::Core::Module
- Included in:
- Module
- Defined in:
- lib/core/module.rb
Class Method Summary collapse
Instance Method Summary collapse
- #alias_method_chain(target, feature) {|aliased_target, punctuation| ... } ⇒ Object
- #ancestor ⇒ Object
- #ancestors_without_self ⇒ Object
- #append_features_with_module_extensions(target) ⇒ Object
- #container ⇒ Object
- #delegate_to_class(source, target = source) ⇒ Object
- #extensions ⇒ Object
- #inheritable_extension(*mods) ⇒ Object
- #self_and_ancestors ⇒ Object
Class Method Details
.included(klass) ⇒ Object
4 5 6 |
# File 'lib/core/module.rb', line 4 def self.included(klass) klass.alias_method_chain :append_features, :module_extensions end |
Instance Method Details
#alias_method_chain(target, feature) {|aliased_target, punctuation| ... } ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/core/module.rb', line 8 def alias_method_chain(target, feature) # Strip out punctuation on predicates or bang methods since # e.g. target?_without_feature is not a valid method name. aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1 yield(aliased_target, punctuation) if block_given? with_method, without_method = "#{aliased_target}_with_#{feature}#{punctuation}", "#{aliased_target}_without_#{feature}#{punctuation}" alias_method without_method, target alias_method target, with_method case when public_method_defined?(without_method) public target when protected_method_defined?(without_method) protected target when private_method_defined?(without_method) private target end end |
#ancestor ⇒ Object
71 72 73 |
# File 'lib/core/module.rb', line 71 def ancestor ancestors_without_self.first end |
#ancestors_without_self ⇒ Object
66 67 68 69 |
# File 'lib/core/module.rb', line 66 def ancestors_without_self result = ancestors result.first == self ? result.drop(1) : result end |
#append_features_with_module_extensions(target) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/core/module.rb', line 44 def append_features_with_module_extensions(target) append_features_without_module_extensions(target) if @inheritable_extensions target.extend *@inheritable_extensions target.inheritable_extension *@inheritable_extensions.reverse end end |
#container ⇒ Object
31 32 33 34 |
# File 'lib/core/module.rb', line 31 def container space = name[0...(name.rindex( '::' ) || 0)] space.empty? ? Object : eval(space) end |
#delegate_to_class(source, target = source) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/core/module.rb', line 52 def delegate_to_class(source, target=source) define_method(source) do |*args, &block| singleton_class_eval do send(target, *args, &block) end end end |
#extensions ⇒ Object
36 37 38 |
# File 'lib/core/module.rb', line 36 def extensions singleton_class.ancestors.take_while { |mod| !mod.is_a?(Class) } end |
#inheritable_extension(*mods) ⇒ Object
40 41 42 |
# File 'lib/core/module.rb', line 40 def inheritable_extension(*mods) (@inheritable_extensions ||= []).unshift(mods.reverse).flatten!.uniq! end |
#self_and_ancestors ⇒ Object
60 61 62 63 64 |
# File 'lib/core/module.rb', line 60 def self_and_ancestors result = ancestors result.unshift self unless result.first == self result end |