Created
July 31, 2008 22:16
-
-
Save chriseppstein/3535 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module IgnoringDiff | |
| def ignore_difference_for(key) | |
| self.extend(Module.new do | |
| define_method :diff do |*arguments| | |
| returning(super(*arguments)) do |difference| | |
| difference.delete(key) | |
| end | |
| end | |
| end) | |
| end | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'ignoring_diff' | |
| Hash.send(:include, IgnoringDiff) | |
| h = {:foo => :bar} | |
| h.diff({}) | |
| # => {:foo => :bar} | |
| h.ignore_difference_for(:foo) | |
| h.diff({}) | |
| # => {} | |
| h.diff({:bar => :baz}) | |
| # => {:bar => :baz} | |
| h.ignore_difference_for(:bar) | |
| h.diff({:bar => :baz}) | |
| # => {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment