[#97086] [Ruby master Bug#16612] Enumerator::ArithmeticSequence#last with float range produces incorrect value — muraken@...
Issue #16612 has been updated by mrkn (Kenta Murata).
4 messages
2020/02/07
[#97307] [Ruby master Feature#16663] Add block or filtered forms of Kernel#caller to allow early bail-out — headius@...
Issue #16663 has been reported by headius (Charles Nutter).
29 messages
2020/02/28
[ruby-core:97073] [Ruby master Bug#14909] Method call with object that has to_hash method crashes (method with splat and keyword arguments)
From:
merch-redmine@...
Date:
2020-02-06 14:22:41 UTC
List:
ruby-core #97073
Issue #14909 has been updated by jeremyevans0 (Jeremy Evans).
AlexWayfer (Alexander Popov) wrote in #note-7:
> There are problems with Sequel Models, which have `#to_hash` method (implicit conversion), and Memery gem, which defines methods with `*args, **kwargs, &block` (`**kwargs` was added after warning from Ruby 2.7).
Memery may want to switch to using `ruby2_keywords` instead.
> So, Sequel Models as arguments for memoized methods becomes Hashes and it breaks everything.
>
> The `**(;{})` approach is:
>
> * unclear for me (what it does in Ruby?);
It passes empty keywords, so that the final positional object is not treated as a hash.
> * additional changes at every call;
Should not be necessary with the `ruby2_keywords` approach.
> * offenses RuboCop (should be resolved there, yes).
>
> I'll try to make dynamic methods definition in Memery with exactly expected parameters instead of `*args, **kwargs, &block`, but it's harder.
>
> And, probably, impossible at all, like `define_method(:bar) do |*instance_method(:foo).parameters|`. Only `eval`, I guess.
`*args, &block` as arguments and `ruby2_keywords :bar` after defining the method should work, and that is the approach I would recommend.
----------------------------------------
Bug #14909: Method call with object that has to_hash method crashes (method with splat and keyword arguments)
https://bugs.ruby-lang.org/issues/14909#change-84179
* Author: johannes_luedke (Johannes Lke)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin17]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
In a method with a splat method argument followed by a keyword argument, it leads to an `ArgumentError` when calling the method with an object that reacts to `to_hash`
~~~ruby
def my_func(*objects, error_code: 400)
objects.inspect
end
class Test
def to_hash
# an example hash
{ to_hash_key: "to_hash" }
end
end
my_func(Test.new)
~~~
Observed result: an exception is raised: `in my_func: unknown keyword: to_hash_key (ArgumentError)`
Expected result: `[#<Test:0x007fc8c9825318>]` is returned by the `my_func` call
It should behave the same when calling with objects that have a `to_hash` method and objects that don't, shouldn't it?
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>