Created
December 2, 2015 22:10
-
-
Save abargnesi/ba98ed5686405aed36a5 to your computer and use it in GitHub Desktop.
Read ruby "configuration" script using instance_eval.
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 Configuration | |
| def self.configured_components | |
| @components | |
| end | |
| def self.component(key) | |
| return unless block_given? | |
| @components ||= {} | |
| @components[key] = yield | |
| end | |
| end | |
| Configuration.instance_eval(DATA.read) | |
| require 'pp' | |
| pp Configuration.configured_components | |
| __END__ | |
| # configure foo component | |
| component(:foo) do | |
| :bar | |
| end | |
| # configure bar component | |
| component(:bar) do | |
| :baz | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment