Skip to content
/ swap Public

Ruby lib that allows dynamically replacing and restoring methods

License

Notifications You must be signed in to change notification settings

mynyml/swap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

==== 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

About

Ruby lib that allows dynamically replacing and restoring methods

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages