Created
March 14, 2015 10:07
-
-
Save wojtekmach/d2fd480f063adec074f6 to your computer and use it in GitHub Desktop.
anima_ext.rb
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 '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