Project

General

Profile

Actions

Bug #11130

closed

Re: [ruby-changes:38376] glass:r50457 (trunk): * enum.c (enum_to_a): Use size to set array capa when possible.

Added by kou (Kouhei Sutou) almost 9 years ago. Updated almost 9 years ago.

Status:
Closed
Target version:
-
[ruby-dev:48959]

Description

須藤です。

+    if (NIL_P(size) || size == Qundef) {
+	ary = rb_ary_new();
+    }
+    else {
+	ary = rb_ary_new_capa(NUM2LONG(size));
+    }

    if (FIXNUM_P(size)) {
	ary = rb_ary_new_capa(NUM2LONG(size));
    }
    else {
	ary = rb_ary_new();
    }

とかsizeが返す値が数値じゃなかったらこれまでと同じ挙動にする
ようにしてもらえないでしょうか?

これまでは

class NonIntegerSizeEnum
  include Enumerable

  def initialize(n)
    @n = n
  end

  def each
    @n.times { |i| yield i }
  end

  def size
    :size
  end
end

NonIntegerSizeEnum.new(100).to_a

というコードが動いていたんですが、この変更の後からは

/tmp/b.rb:17:in `to_a': no implicit conversion of Symbol into Integer (TypeError)

というエラーがでるようになってしまって困っています。


Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #9118: In Enumerable#to_a, use size to set array capa when possibleClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0