Created
November 21, 2012 22:04
-
-
Save groveriffic/4128166 to your computer and use it in GitHub Desktop.
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
class MetaDerp | |
### DENSE HORRIBLE CODE | |
# This should be broken up into smaller chunks possibly moved out into a mixin | |
# to hide it's horribleness | |
class << self | |
def hunt(name, *keys) | |
class_eval %[ | |
def #{name} | |
#{keys.map{|key| "row[#{key.inspect}]" }.join(' || ')} | |
end | |
] | |
end | |
end | |
### Pretty Expressive Beatiful Code | |
attr_accessor :row | |
hunt :message, :message, :are_you_there?, :hello | |
end | |
m = MetaDerp.new | |
m.row = { :hello => 'Metaprogramming' } | |
puts m.message | |
m.row = { :are_you_there? => 'Yup', :hello => 'Metaprogramming' } | |
puts m.message | |
m.row = { :message => 'It works!' } | |
puts m.message | |
m.row = { :"no one will look here" => 'And why should they?' } | |
puts m.message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment