Skip to content
This repository was archived by the owner on Sep 17, 2022. It is now read-only.

Instance-level configuration #13

Open
jqmtor opened this issue Nov 18, 2015 · 3 comments
Open

Instance-level configuration #13

jqmtor opened this issue Nov 18, 2015 · 3 comments

Comments

@jqmtor
Copy link

jqmtor commented Nov 18, 2015

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.

@beatrichartz
Copy link
Owner

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')

@jqmtor
Copy link
Author

jqmtor commented Nov 18, 2015

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.

@igorlg
Copy link

igorlg commented Sep 25, 2017

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!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants