Created
January 29, 2015 11:26
-
-
Save wobh/6a149f4960bf621d8b96 to your computer and use it in GitHub Desktop.
Minimum configurable Ruby class
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
# Goals | |
# 1. Small class configurable with a block | |
# 2. puts settings in a ruby Struct | |
require 'Forwardable' | |
class Settable | |
extend Forwardable | |
def_delegator :@config, :foo | |
def_delegator :@config, :bar | |
def initialize(&settings) | |
@config = Struct.new(:foo, :bar).new | |
settings.call(@config) if settings | |
@config.freeze | |
end | |
end | |
# TODO: try with a different delegator | |
# FIXME: try not to expose `config' class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment