[#97063] [Ruby master Bug#16608] ConditionVariable#wait should return false when timeout exceeded — shugo@...

Issue #16608 has been reported by shugo (Shugo Maeda).

10 messages 2020/02/05

[#97084] [Ruby master Feature#16614] New method cache mechanism for Guild — ko1@...

Issue #16614 has been reported by ko1 (Koichi Sasada).

18 messages 2020/02/07

[#97248] [Ruby master Bug#16651] Extensions Do Not Compile on Mingw64 — cfis@...

Issue #16651 has been reported by cfis (Charlie Savage).

17 messages 2020/02/24

[#97289] [Ruby master Bug#16658] `method__cache__clear` DTrace hook was dropped without replacement — v.ondruch@...

Issue #16658 has been reported by vo.x (Vit Ondruch).

9 messages 2020/02/27

[#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

[#97310] [Ruby master Feature#16665] Add an Array#except_index method — alexandr1golubenko@...

Issue #16665 has been reported by alex_golubenko (Alex Golubenko).

12 messages 2020/02/29

[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>

In This Thread

Prev Next