Skip to content

Instantly share code, notes, and snippets.

@wojtekmach
Created March 14, 2015 10:07
Show Gist options
  • Save wojtekmach/d2fd480f063adec074f6 to your computer and use it in GitHub Desktop.
Save wojtekmach/d2fd480f063adec074f6 to your computer and use it in GitHub Desktop.
anima_ext.rb
require 'anima'
class AnimaExt < Anima
module ClassMethods
def [](hash)
new(hash)
end
end
module InstanceMethods
def inspect
h = to_h.map { |k, v| "#{k}: #{v.inspect}" }.join(', ')
"%s[%s]" % [self.class.name, h]
end
end
def included(cls)
super
cls.extend ClassMethods
cls.include InstanceMethods
end
end
class Point
include AnimaExt.new(:x, :y)
end
require 'minitest/autorun'
describe "Point" do
it do
p = Point[x: 1, y: 2]
p.inspect.must_equal "Point[x: 1, y: 2]"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment