[#18121] [Ruby 1.8.7 - Bug #405] (Open) ssl.rb:31: [BUG] Bus Error — Anonymous <redmine@...>

Issue #405 has been reported by Anonymous.

14 messages 2008/08/04

[#18130] Re: New array methods cycle, choice, shuffle (plus bug in cycle) — Brian Candler <B.Candler@...>

> Seriously though... Array.first is a noun.

10 messages 2008/08/05

[#18319] NEW Command: absolute_path() -- — "C.E. Thornton" <admin@...>

Core,

14 messages 2008/08/16
[#18321] Re: NEW Command: absolute_path() -- — Yukihiro Matsumoto <matz@...> 2008/08/18

Hi,

[#18381] [Bug #496] DRb.start_service(nil) is very slow — Hongli Lai <redmine@...>

Bug #496: DRb.start_service(nil) is very slow

11 messages 2008/08/25

[ruby-core:18204] Re: New array methods cycle, choice, shuffle (plus bug in cycle)

From: "David A. Black" <dblack@...>
Date: 2008-08-08 16:15:49 UTC
List: ruby-core #18204
Hi --

On Fri, 8 Aug 2008, Charles Oliver Nutter wrote:

> Florian Frank wrote:
>> Yukihiro Matsumoto wrote:
>>> Here are choices:
>>> 
>>> * Array#rand (or random, or random_element): pick one random element
>>>   from an array.  some might confuse the method to behave like
>>>   #shuffle though.
>>> 
>> Because nobody has mentioned this yet: I know, that rails defines a method 
>> with that name in Array, but I think it is a bad idea. It breaks existing 
>> and future code, that expects Array#rand to be Kernel#rand and have the 
>> same signature and semantics of it, while being in context of  an Array 
>> instance. It makes it much more difficult to get any random number out of 
>> ruby in this context, even if you are aware of Array#rand.
>
> Kernel#rand is not callable as a method:
>
> ruby -e "[1,2,3].rand"
> -e:1: private method `rand' called for [1, 2, 3]:Array (NoMethodError)
>
> So this argument would only affect methods calling rand from within instance 
> methods on Array or subclasses of it. I think the danger of overwriting 
> Kernel#rand in a way that would break user code is pretty low.

I know 1.9 has Array#shuffle, so this exact example is probably
somewhat obsolete (except in existing code), but lots of people do:

   class Array
     def shuffle
       replace(sort_by { rand })
     end
   end

which would totally break if Array#rand were not Kernel#rand. I think
Florian is right that it's not a good idea for core classes to
repurpose the names of top-level methods.


David

-- 
Rails training from David A. Black and Ruby Power and Light:
  *  Advancing With Rails    August 18-21    Edison, NJ
  * Co-taught by D.A. Black and Erik Kastner
See http://www.rubypal.com for details and updates!

In This Thread