Sha256: a31e2dcb9fad95296bdb0d26213981c76c2d10cc68c81c90e74b580ff2211877

Contents?: true

Size: 578 Bytes

Versions: 8

Compression:

Stored size: 578 Bytes

Contents

require 'mocha/singleton_class'

module MethodDefiner
  def define_instance_method(object, method_symbol, &block)
    object.singleton_class.send(:define_method, method_symbol, block)
  end

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

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mocha-1.11.2 test/method_definer.rb
mocha-1.11.1 test/method_definer.rb
mocha-1.11.0 test/method_definer.rb
mocha-1.10.2 test/method_definer.rb
mocha-1.10.1 test/method_definer.rb
mocha-1.10.0 test/method_definer.rb
mocha-1.10.0.beta.1 test/method_definer.rb
mocha-1.10.0.alpha test/method_definer.rb