Created
December 28, 2012 23:41
-
-
Save shepmaster/4403172 to your computer and use it in GitHub Desktop.
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
| module X | |
| def type(code, name) | |
| instance_eval do | |
| define_method "#{name}?" do |type| | |
| type == code | |
| end | |
| end | |
| end | |
| end | |
| class Foo | |
| extend X | |
| type 0, :integer | |
| type 1, :string | |
| end | |
| describe Foo do | |
| it "knows if it is an integer" do | |
| subject.should be_integer(0) | |
| end | |
| it "knows if it is not an integer" do | |
| subject.should_not be_integer(1) | |
| end | |
| it "knows if it is a string" do | |
| subject.should be_string(1) | |
| end | |
| end | |
| describe X do | |
| class Bar | |
| extend X | |
| type 99, :cat | |
| end | |
| it "associates a name with a type code" do | |
| Bar.new.should be_cat(99) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment