Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/git_workflow/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#alias_method_chain(method, chain) ⇒ Object



85
86
87
88
89
90
# File 'lib/git_workflow/core_ext.rb', line 85

def alias_method_chain(method, chain)
  chain_methods(method, chain) do |with_chain_method, without_chain_method|
    alias_method(without_chain_method, method)
    alias_method(method, with_chain_method)
  end
end

#chain_methods(method, chain) {|with_chain_method, without_chain_method| ... } ⇒ Object

Yields:

  • (with_chain_method, without_chain_method)


77
78
79
80
81
82
83
# File 'lib/git_workflow/core_ext.rb', line 77

def chain_methods(method, chain, &block)
  match                  = method.to_s.match(/^([^!\?]+)([!\?])?$/) or raise StandardError, "Cannot match '#{ method }' as a method"
  method_core, extension = match[ 1 ], match[ 2 ]
  with_chain_method    = :"#{ method_core }_with_#{ chain }#{ extension }"
  without_chain_method = :"#{ method_core }_without_#{ chain }#{ extension }"
  yield(with_chain_method, without_chain_method)
end

#delegate(name, options) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/git_workflow/core_ext.rb', line 99

def delegate(name, options)
  class_eval <<-END_OF_DELEGATION
    def #{ name }(*args, &block)
      #{ options[ :to ] }.#{ name }(*args, &block)
    end
  END_OF_DELEGATION
end

#unalias_method_chain(method, chain) ⇒ Object



92
93
94
95
96
97
# File 'lib/git_workflow/core_ext.rb', line 92

def unalias_method_chain(method, chain)
  chain_methods(method, chain) do |with_chain_method, without_chain_method|
    alias_method(method, without_chain_method)
    undef_method(without_chain_method)
  end
end