Sha256: 4bf260aa9cdb9a1f50f84252ead3ca5229b5450a5445b4e1eadc74874bcb2eb9

Contents?: true

Size: 1.22 KB

Versions: 28

Compression:

Stored size: 1.22 KB

Contents

#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-
# Copyright muflax <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

28 entries across 28 versions & 1 rubygems

Version Path
muflax-0.5.1 lib/muflax/objects.rb
muflax-0.5.0 lib/muflax/objects.rb
muflax-0.4.2 lib/muflax/objects.rb
muflax-0.4.1 lib/muflax/objects.rb
muflax-0.4.0 lib/muflax/objects.rb
muflax-0.3.23 lib/muflax/objects.rb
muflax-0.3.22 lib/muflax/objects.rb
muflax-0.3.21 lib/muflax/objects.rb
muflax-0.3.20 lib/muflax/objects.rb
muflax-0.3.19 lib/muflax/objects.rb
muflax-0.3.18 lib/muflax/objects.rb
muflax-0.3.17 lib/muflax/objects.rb
muflax-0.3.16 lib/muflax/objects.rb
muflax-0.3.14 lib/muflax/objects.rb
muflax-0.3.13 lib/muflax/objects.rb
muflax-0.3.12 lib/muflax/objects.rb
muflax-0.3.11 lib/muflax/objects.rb
muflax-0.3.10 lib/muflax/objects.rb
muflax-0.3.9 lib/muflax/objects.rb
muflax-0.3.8 lib/muflax/objects.rb