[ruby-dev:49892] [Ruby trunk Misc#13003] About not Random instance of random: keyword ardument of Array#shuffle!

From: ksmakoto@...4u.or.jp
Date: 2016-12-04 04:46:55 UTC
List: ruby-dev #49892
Issue #13003 has been reported by Makoto Kishimoto.

----------------------------------------
Misc #13003: About not Random instance of random: keyword ardument of Array#shuffle! 
https://bugs.ruby-lang.org/issues/13003

* Author: Makoto Kishimoto
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Array#shuffle! の random: キーワード引数で、Randomのインスタンスでないような
任意のオブジェクトを渡してしまっていても、(最終的に)rb_random_ulong_limited 中の
rb_funcallv(obj, id_rand, 1, &lim) という呼び出しによりグローバルの rand が
呼び出されて、それっぽく動いてしまいます。

わざわざ random: キーワード引数で渡していながら、変なオブジェクトを渡してしまって
いる、というのは、ユーザのスクリプトのバグである可能性が高いと思うのですが、
それでもそれっぽく動いてしまうようになっている、というのは、そのように意図されて
いるものでしょうか?



-- 
https://bugs.ruby-lang.org/

In This Thread

Prev Next