File: copies_methods.rb

package info (click to toggle)
ruby-bogus 0.1.5-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 828 kB
  • ctags: 628
  • sloc: ruby: 4,124; makefile: 6; sh: 2
file content (33 lines) | stat: -rw-r--r-- 771 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module Bogus
  class CopiesMethods
    extend Takes

    takes :makes_substitute_methods,
      :method_copiers,
      :copies_constructor

    def copy(from, into)
      method_copiers.each do |copier|
        copy_methods(from, into, copier)
      end
      copies_constructor.copy(from, into)
    end

    private

    def copy_methods(original_class, copy_class, make_methods)
      original_methods = make_methods.call(original_class)
      copy_methods = make_methods.call(copy_class)

      original_methods.all.each do |name|
        method = original_methods.get(name)
        body = method_as_string(method)
        copy_methods.define(body)
      end
    end

    def method_as_string(method)
      makes_substitute_methods.stringify(method)
    end
  end
end