Sha256: 152f40c1d5e39f8e9bf49a4967518ae73624111feee6a64f01c4849b0fd36b11
Contents?: true
Size: 1.22 KB
Versions: 3
Compression:
Stored size: 1.22 KB
Contents
#!/usr/bin/env ruby # -*- encoding: utf-8 -*- # Copyright Steffie Dorn <mail@muflax.com>, 2013 # License: GNU GPL 3 <http://www.gnu.org/copyleft/gpl.html> # make it possible to track data in attributes class Class alias_method :attr_reader_without_tracking, :attr_reader def attr_reader(*names) attr_readers.concat(names) attr_reader_without_tracking(*names) end def attr_readers @attr_readers ||= [ ] end alias_method :attr_writer_without_tracking, :attr_writer def attr_writer(*names) attr_writers.concat(names) attr_writer_without_tracking(*names) end def attr_writers @attr_writers ||= [ ] end alias_method :attr_accessor_without_tracking, :attr_accessor def attr_accessor(*names) attr_readers.concat(names) attr_writers.concat(names) attr_accessor_without_tracking(*names) end def attributes attr_readers + attr_writers end end class Object def differences_with(other) # get list of all attributes attrs = (self.class.attr_readers + self.class.attr_writers).uniq.sort # pick all attributes that they disagree about attrs.reject do |attr| self.respond_to? attr and other.respond_to? attr and self.send(attr) == other.send(attr) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
muflax-0.5.5 | lib/muflax/objects.rb |
muflax-0.5.3 | lib/muflax/objects.rb |
muflax-0.5.2 | lib/muflax/objects.rb |