configurations icon indicating copy to clipboard operation
configurations copied to clipboard

Instance-level configuration

Open jqmtor opened this issue 9 years ago • 3 comments

I think it would be great to have instance specific configuration that takes precedence over the class-level configuration.

Example:

MyGem.new do |config|
  config.foo = 'bar'
end

Does this make sense? I find it useful when multiple configurations are needed or even for testing purposes.

jqmtor avatar Nov 18 '15 14:11 jqmtor

Interesting - could you elaborate on the use case a little bit more, specifically how this would be different from instantiating classes in your gem with parameters? e.g. :

MyGem.new(foo: 'bar')

beatrichartz avatar Nov 18 '15 18:11 beatrichartz

I could definitely do what you said, and simply pass the configuration in on MyGem initialization, but I was thinking it would be cool to have the same facilities and interface you created for the class-level configuration. One clear advantage is that it would be possible to take advantage of the restricted configuration options, for example.

jqmtor avatar Nov 18 '15 22:11 jqmtor

Agreed! Your method is amazing, and I would really love to use it when instantiating objects. i.e. This:

obj = MyClass.new do |c|
  c.conf1 = 'abc'
  c.param2 = [1, 2, 3]
end

looks better to me than this:

obj = MyClass.new('abc', [1,2,3])

Anyway, Kudos for the project!

igorlg avatar Sep 25 '17 22:09 igorlg