Module: Wrapper

Included in:
Wrapped
Defined in:
lib/contracts-ruby2/benchmarks/wrap_test.rb,
lib/contracts-ruby3/benchmarks/wrap_test.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(klass) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/contracts-ruby2/benchmarks/wrap_test.rb', line 4

def self.extended(klass)
  klass.class_eval do
    @@methods = {}
    def self.methods
      @@methods
    end
    def self.set_method k, v
      @@methods[k] = v
    end
  end
end

Instance Method Details

#method_added(name) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/contracts-ruby2/benchmarks/wrap_test.rb', line 16

def method_added name
  return if methods.include?(name)
  puts "#{name} added"
  set_method(name, instance_method(name))
  class_eval %{
    def #{name}(*args)
      self.class.methods[#{name.inspect}].bind(self).call(*args)
    end
  }, __FILE__, __LINE__ + 1
end