Skip to content

Instantly share code, notes, and snippets.

@abargnesi
Created December 2, 2015 22:10
Show Gist options
  • Select an option

  • Save abargnesi/ba98ed5686405aed36a5 to your computer and use it in GitHub Desktop.

Select an option

Save abargnesi/ba98ed5686405aed36a5 to your computer and use it in GitHub Desktop.
Read ruby "configuration" script using instance_eval.
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