rubyconfig / config

Easiest way to add multi-environment yaml settings to Rails, Sinatra, Padrino and other Ruby projects.
Other
2.1k stars 230 forks source link

Prevent name collision with private methods from ancestors #351

Closed vadtel closed 6 months ago

vadtel commented 7 months ago

I caught error when accessing an option named lambda

>> config['lambda']
# ArgumentError: tried to create Proc object without a block
from bundle/ruby/2.6.0/gems/config-2.2.3/lib/config/options.rb:161:in `lambda'

The methods used to access options are always public, so there is no need to use send. Using send can cause problems because it can call private and protected methods of the base classes. I replaced send with public_send. This will avoid the problems caused by send calling private and protected methods.

pkuczynski commented 6 months ago

@cjlarose are you happy with the change? I would like to merge it and release it as 5.2.0

pkuczynski commented 6 months ago

@vadtel tests are failing for Ruby 3.0. Would you mind having a look?

vadtel commented 6 months ago

@vadtel tests are failing for Ruby 3.0. Would you mind having a look?

It depends on the ostruct version We don't create singleton methods for fields with exclamation marks (bangs) how return respond_to?(name, true) - true The method_missing method only returns nil in one version of Ruby https://github.com/ruby/ostruct/commit/69cbbefd997f74b99b5135db8b9ef1ba97a31b43 May be we need to return "exit!" to constant?

pkuczynski commented 6 months ago

May be we need to return "exit!" to constant?

Yeah, possibly this would be the easiest solution. @cjlarose wdyt?

pkuczynski commented 6 months ago

Waiting for the feedback from @cjlarose before we merge it in and release it. Hopefully soon...

cjlarose commented 6 months ago

Released with version 5.2.0