Created
August 31, 2012 10:36
-
-
Save undecided/3551304 to your computer and use it in GitHub Desktop.
How do I do this?
This file contains 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
# Premise: a chainable DSL where evaluating a section in an if statement calls valid? | |
# Example: Each item changes the current synonym, it tests it against | |
class Moggy | |
SYNONYMS = [:cat, :moggy, :pussycat, :feline] | |
def set(syn) | |
@synonym = syn | |
self | |
end | |
def valid? | |
SYNONYMS.include? @synonym | |
end | |
end | |
m = Moggy.new | |
m.set(:pussycat).set(:dog).valid? #=> false | |
if(m) | |
raise "Fail" # is there any way of preventing this result? | |
else | |
"Correct!" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In case you were expecting a real-world example, I would like to be able to do this