Commit 26a9ed4
committed
Fix publishing events responding to #to_hash on Ruby 2.7
When a method accepts both splatted positional & keyword parameters and
a single argument responding to `#to_hash` is given, the argument is
coerced to hash and assigned to the keyword arguments.
E.g.:
class Hashable
def to_hash
{ im: :a_hash }
end
end
def method_with_splat_on_the_positional_argument(*args, **kwargs) # method_with_splat_on_the_positional_argument(Hashable.new)
puts args.inspect # => []
puts kwargs.inspect # => {:im=>:a_hash}
end
However,
def method_without_splat_on_the_positional_argument(args, **kwargs) # method_without_splat_on_the_positional_argument(Hashable.new)
puts args.inspect # => #<Hashable:0x000055cfe8b072b0>
puts kwargs.inspect # => {}
end
We fix the problem on the Spree::Bus override by being explicit about
the expected parameters.
References solidusio/solidus_stripe#157 (comment)1 parent 1c4b1ff commit 26a9ed4
1 file changed
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
0 commit comments