File: method_definer.rb

package info (click to toggle)
ruby-mocha 1.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 1,440 kB
  • sloc: ruby: 11,613; makefile: 13
file content (22 lines) | stat: -rw-r--r-- 599 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
require 'metaclass'

module Mocha
  module ObjectMethods
    def define_instance_method(method_symbol, &block)
      __metaclass__.send(:define_method, method_symbol, block)
    end

    def replace_instance_method(method_symbol, &block)
      raise "Cannot replace #{method_symbol} as #{self} does not respond to it." unless respond_to?(method_symbol)
      define_instance_method(method_symbol, &block)
    end

    def define_instance_accessor(*symbols)
      symbols.each { |symbol| __metaclass__.send(:attr_accessor, symbol) }
    end
  end
end

class Object
  include Mocha::ObjectMethods
end