apotonick / declarative-option

Dynamic Options to evaluate at runtime.
MIT License
7 stars 7 forks source link

Ruby 2.7 compatibility #2

Open silviusimeria opened 3 years ago

silviusimeria commented 3 years ago

I get this warning because Ruby 2.7 deprecated the use of hashes in the last argument of a method call.

gems/ruby-2.7.1@someproject/gems/declarative-option-0.1.0/lib/declarative/option.rb:24: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
johansenja commented 3 years ago

I came across the same problem (I was using the representable gem, which uses this as a dependency) - the problem for me was when I was specifying custom getters for properties like so:

class MyDecorator < Representable::Decorator
  property :foo, getter: ->(represented:, **) { represented.bar }
end

My solution was to just change the args to options:

class MyDecorator < Representable::Decorator
  property :foo, getter: ->(options) { options[:represented].bar }
end

I definitely prefer the clarity of keyword arguments, but this way it silenced all of the warnings and was fairly low effort