Skip to content

Instantly share code, notes, and snippets.

@tatey
Created January 2, 2013 09:43
Show Gist options
  • Save tatey/4433315 to your computer and use it in GitHub Desktop.
Save tatey/4433315 to your computer and use it in GitHub Desktop.
module Countable
def self.included do
define_method "#{self.name}s" do
# ...
end
end
def self.name
self.class.to_s.sub('FeedItem', '').downcase
end
end
class DonationFeedItem
include Countable
end
item = DonationFeedItem.new
item.donations
class CountableTest < MiniTest::Unit::TestCase
class TestFeedItem
include Countable
end
def test_plural_method
item = TestFeedItem.new
assert item.tests
end
end
class DonationFeedItemTest < MiniTest::UnitTestCase
def test_countable
assert_includes DonationFeedItem.constants, Countable
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment