Module: CopyMethod

Defined in:
lib/copy_method.rb,
lib/copy_method/utils.rb,
lib/copy_method/version.rb,
lib/copy_method/integration.rb,
lib/copy_method/copied_method.rb,
lib/copy_method/method_copier.rb

Defined Under Namespace

Modules: Integration, Utils Classes: CopiedMethod, MethodCopier

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.copy_method(name, from:, to:, **kwargs) ⇒ Symbol Also known as: copy

Returns the method name moved.

Parameters:

  • name (Symbol)
  • from (Class, Module)
  • to (Class, Module)
  • singleton (Boolean)
  • remove (Boolean)
  • singleton_target (Boolean)

Returns:

  • (Symbol)

    the method name moved



18
19
20
21
22
23
24
25
26
# File 'lib/copy_method.rb', line 18

def copy_method(name, from:, to:, **kwargs)
  kwargs[:name] = name
  kwargs[:from] = from
  kwargs[:to]   = to

  copier = CopyMethod::MethodCopier.new **kwargs

  copier.copy!
end

.copy_singleton_method(name, **kwargs) ⇒ Object Also known as: copy_singleton



34
35
36
37
38
# File 'lib/copy_method.rb', line 34

def copy_singleton_method(name, **kwargs)
  kwargs[:singleton] = true

  copy_method name, **kwargs
end

.extend_object(base) ⇒ Object Also known as: prepend_features, append_features



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/copy_method.rb', line 53

def extend_object(base)
  verb = case __method__
         when :extend_object    then 'extend'
         when :append_features  then 'include'
         when :prepend_features then 'prepend'
           # :nocov:
           'extend'
           # :nocov:
         end

  $stderr.puts "Do not #{verb} CopyMethod directly. Use CopyMethod.patch! if you want methods in classes directly."
end

.move_method(name, **kwargs) ⇒ Object Also known as: move



28
29
30
31
32
# File 'lib/copy_method.rb', line 28

def move_method(name, **kwargs)
  kwargs[:remove] = true

  copy_method name, **kwargs
end

.move_singleton_method(name, **kwargs) ⇒ Object Also known as: move_singleton



40
41
42
43
44
45
# File 'lib/copy_method.rb', line 40

def move_singleton_method(name, **kwargs)
  kwargs[:singleton]  = true
  kwargs[:remove]     = true

  copy_method name, **kwargs
end

.patch!Object



69
70
71
# File 'lib/copy_method.rb', line 69

def patch!
  Module.include CopyMethod::Integration
end