Created
October 28, 2009 18:03
-
-
Save dmichael/220660 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
| # Make.believe | |
| # A class that creates any class real just by believing. | |
| class Make | |
| class << self | |
| def believe(dream) | |
| classify(dream) | |
| realize(dream) | |
| end | |
| def reality | |
| Class.new { | |
| def self.real? | |
| true | |
| end | |
| } | |
| end | |
| def realize(dream) | |
| real?(dream) ? Object.const_get(dream) : Object.const_set(dream, reality) | |
| end | |
| def real?(dream) | |
| Object.const_defined?(dream) | |
| end | |
| def classify(dream) | |
| dream.gsub!(/^[a-z]|\s+[a-z]/) { |a| a.upcase } | |
| dream.gsub!(/\s/, '') | |
| end | |
| end | |
| end | |
| puts Make.believe("I can fly") | |
| # => ICanFly | |
| puts Make.believe("I can fly").real? | |
| # => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment