File: constructor_methods.rb

package info (click to toggle)
ruby-bogus 0.1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 860 kB
  • sloc: ruby: 4,219; makefile: 8; sh: 2
file content (18 lines) | stat: -rw-r--r-- 479 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
module Bogus
  class CopiesConstructor
    extend Takes
    takes :method_stringifier, :instance_methods, :class_methods

    def copy(from, into)
      return unless from.is_a?(Class)
      initializer = instance_methods.call(from).get(:initialize)
      body = body(initializer)
      class_methods.call(into).define(body)
    end

    def body(initializer)
      body = method_stringifier.stringify(initializer, "super")
      body.gsub("initialize", "new")
    end
  end
end