public
Description: Ruby lib that allows dynamically replacing and restoring methods
Homepage:
Clone URL: git://github.com/mynyml/swap.git
swap /
name age message
file .gitignore Tue Sep 22 10:56:01 -0700 2009 Add docs watchr script [mynyml]
file LICENSE Sun Mar 15 22:34:08 -0700 2009 Add license. [mynyml]
file README Tue Sep 22 10:36:19 -0700 2009 Update README [mynyml]
file Rakefile Tue Sep 22 10:55:08 -0700 2009 Clean up Rakefile, gemspec [mynyml]
file TODO Sun Mar 15 21:04:24 -0700 2009 Initial commit. [mynyml]
file docs.watchr Tue Sep 22 10:56:01 -0700 2009 Add docs watchr script [mynyml]
directory examples/ Wed Sep 23 07:31:37 -0700 2009 Update examples file [mynyml]
file gem.watchr Tue Sep 22 11:01:30 -0700 2009 Add gem watchr script [mynyml]
directory lib/ Tue Sep 22 10:20:50 -0700 2009 Update source docs [mynyml]
file specs.watchr Tue Sep 22 10:28:50 -0700 2009 Update example file [mynyml]
file swap.gemspec Wed Sep 23 07:33:34 -0700 2009 v0.2 [mynyml]
directory test/ Wed Sep 23 12:22:45 -0700 2009 Add specs for arguments/block [mynyml]
README
==== Summary

Swap allows dynamically replacing and restoring methods.
Useful as a stubbing device, as it allows unstubbing as well.

==== Examples

  require 'swap'

  class User
    extend Swappable

    attr_writer :name
    def name
      @name
    end
  end

  user = User.new
  user.name = 'martin'
  user.name #=> 'martin'

  User.swap!(:name) { @name.reverse }
  user.name #=> 'nitram'

  User.unswap!(:name)
  user.name #=> 'martin'

Calling #unswap! without argument will restore all swapped methods.

See also examples/simple.rb