[#46647] RubyでWindowsの常駐サービスプログラムを作る方法 — kouichi_someya@...

はじめまして。

12 messages 2009/12/16
[#46649] Re: RubyでWindowsの常駐サービスプログラムを作る方法 — "U.Nakamura" <usa@...> 2009/12/17

こんにちは、なかむら(う)です。

[ruby-list:46585] Re: ActiveRecordとArrayのchoiceメソッドでエラー(1.8.7)

From: Gen Ito <it0gn.25@...>
Date: 2009-12-01 05:22:03 UTC
List: ruby-list #46585
itogです。

> さくさん
ありがとうございます。

> 1.8.7 には Array#choice は定義されているような。

ほんとだ、、、choiceがないのは1.8.6までですね。

choiceを置き換えなければそもそも発生しない問題でした。
1.8.6でもKernel.rand()で明示的に組み込みメソッドを呼べば
いいんですね。

重ね重ね、ありがとうございます。

----
itog


2009/12/1 OZAWA Sakuro <sakuro@2238club.org>:
> さくです。
>
> 2009年12月1日12:47 Gen Ito <it0gn.25@gmail.com>:
>
>> Ruby 1.8.7で、Array:choiceを使うため、逆引きRubyに載っている
>> 方法を使っているのですが、
>
> 1.8.7 には Array#choice は定義されているような。
>
> $ ruby -ve 'p 20.times.map { [1,2,3].choice }'
> ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9]
> [1, 2, 3, 2, 2, 1, 2, 3, 3, 3, 1, 3, 2, 2, 2, 3, 3, 1, 2, 2]
>
>> このchoiceメソッドを、ActiveRecordと一緒に使った場合に
>> エラーになってしまいます(コードは後述)。
>
>> in `rand': wrong number of arguments (1 for 0) (ArgumentError)
>
> active_recordがactive_supportを使用していますが、active_supportで
> choiceと同等の動作をする Array#rand (引数なし) が定義されています。
> active_support/core_ext/array/random_access.rb
>
> レシーバを略すと self(=Array)#rand が使われてしまうので、
> Array#choiceを自分で定義する場合は Kernel.rand を使う必要があります。
>
> --
> OZAWA Sakuro
>
> "The future will be better tomorrow." --Dan Quayle
>
>

In This Thread

Prev Next