Skip to content

Instantly share code, notes, and snippets.

@dmichael
Created October 28, 2009 18:03
Show Gist options
  • Select an option

  • Save dmichael/220660 to your computer and use it in GitHub Desktop.

Select an option

Save dmichael/220660 to your computer and use it in GitHub Desktop.
# 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