Removed `to_ary` conversion method.

parent b6c5e501
......@@ -199,6 +199,7 @@ MRB_API void mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val
* @param other The array to replace it with.
*/
MRB_API void mrb_ary_replace(mrb_state *mrb, mrb_value self, mrb_value other);
MRB_API mrb_value mrb_array_type(mrb_state *mrb, mrb_value self);
MRB_API mrb_value mrb_check_array_type(mrb_state *mrb, mrb_value self);
/*
......
# coding: cp932
class Array
##
# call-seq:
......@@ -757,16 +758,6 @@ class Array
nil
end
##
# call-seq:
# ary.to_ary -> ary
#
# Returns +self+.
#
def to_ary
self
end
##
# call-seq:
# ary.dig(idx, ...) -> object
......
......@@ -323,27 +323,11 @@ assert('Array#to_h') do
assert_raise(ArgumentError) { [[1]].to_h }
end
assert('Array#to_h (Modified)') do
class A
def to_ary
$a.clear
nil
end
end
$a = [A.new]
assert_raise(TypeError) { $a.to_h }
end
assert("Array#index (block)") do
assert_nil (1..10).to_a.index { |i| i % 5 == 0 and i % 7 == 0 }
assert_equal 34, (1..100).to_a.index { |i| i % 5 == 0 and i % 7 == 0 }
end
assert("Array#to_ary") do
assert_equal [], [].to_ary
assert_equal [1,2,3], [1,2,3].to_ary
end
assert("Array#dig") do
h = [[[1]], 0]
assert_equal(1, h.dig(0, 0, 0))
......
......@@ -621,9 +621,7 @@ module Enumerable
# use Enumerator to use infinite sequence
def zip(*args, &block)
args = args.map do |a|
if a.respond_to?(:to_ary)
a.to_ary.to_enum(:each)
elsif a.respond_to?(:each)
if a.respond_to?(:each)
a.to_enum(:each)
else
raise TypeError, "wrong argument type #{a.class} (must respond to :each)"
......
......@@ -161,9 +161,7 @@ mrb_f_string(mrb_state *mrb, mrb_value self)
* call-seq:
* Array(arg) -> array
*
* Returns +arg+ as an Array.
*
* First tries to call Array#to_ary on +arg+, then Array#to_a.
* Returns +arg+ as an Array using to_a method.
*
* Array(1..5) #=> [1, 2, 3, 4, 5]
*
......@@ -174,10 +172,7 @@ mrb_f_array(mrb_state *mrb, mrb_value self)
mrb_value arg, tmp;
mrb_get_args(mrb, "o", &arg);
tmp = mrb_check_convert_type(mrb, arg, MRB_TT_ARRAY, "Array", "to_ary");
if (mrb_nil_p(tmp)) {
tmp = mrb_check_convert_type(mrb, arg, MRB_TT_ARRAY, "Array", "to_a");
}
tmp = mrb_check_convert_type(mrb, arg, MRB_TT_ARRAY, "Array", "to_a");
if (mrb_nil_p(tmp)) {
return mrb_ary_new_from_values(mrb, 1, &arg);
}
......
......@@ -1058,7 +1058,7 @@ mrb_ary_rindex_m(mrb_state *mrb, mrb_value self)
MRB_API mrb_value
mrb_ary_splat(mrb_state *mrb, mrb_value v)
{
mrb_value a, recv_class;
mrb_value a;
if (mrb_array_p(v)) {
return v;
......@@ -1069,22 +1069,11 @@ mrb_ary_splat(mrb_state *mrb, mrb_value v)
}
a = mrb_funcall(mrb, v, "to_a", 0);
if (mrb_array_p(a)) {
return a;
}
else if (mrb_nil_p(a)) {
if (mrb_nil_p(a)) {
return mrb_ary_new_from_values(mrb, 1, &v);
}
else {
recv_class = mrb_obj_value(mrb_obj_class(mrb, v));
mrb_raisef(mrb, E_TYPE_ERROR, "can't convert %S to Array (%S#to_a gives %S)",
recv_class,
recv_class,
mrb_obj_value(mrb_obj_class(mrb, a))
);
/* not reached */
return mrb_undef_value();
}
mrb_array_type(mrb, a);
return a;
}
static mrb_value
......@@ -1121,12 +1110,6 @@ mrb_ary_empty_p(mrb_state *mrb, mrb_value self)
return mrb_bool_value(ARY_LEN(a) == 0);
}
MRB_API mrb_value
mrb_check_array_type(mrb_state *mrb, mrb_value ary)
{
return mrb_check_convert_type(mrb, ary, MRB_TT_ARRAY, "Array", "to_ary");
}
MRB_API mrb_value
mrb_ary_entry(mrb_value ary, mrb_int offset)
{
......@@ -1180,7 +1163,7 @@ join_ary(mrb_state *mrb, mrb_value ary, mrb_value sep, mrb_value list)
val = tmp;
goto str_join;
}
tmp = mrb_check_convert_type(mrb, val, MRB_TT_ARRAY, "Array", "to_ary");
tmp = mrb_check_array_type(mrb, val);
if (!mrb_nil_p(tmp)) {
val = tmp;
goto ary_join;
......
......@@ -520,7 +520,8 @@ to_str(mrb_state *mrb, mrb_value val)
static mrb_value
to_ary(mrb_state *mrb, mrb_value val)
{
return check_type(mrb, val, MRB_TT_ARRAY, "Array", "to_ary");
CHECK_TYPE(mrb, val, MRB_TT_ARRAY, "Array");
return val;
}
static mrb_value
......
......@@ -606,6 +606,23 @@ mrb_check_string_type(mrb_state *mrb, mrb_value str)
return str;
}
MRB_API mrb_value
mrb_array_type(mrb_state *mrb, mrb_value ary)
{
if (!mrb_array_p(ary)) {
mrb_raisef(mrb, E_TYPE_ERROR, "%S cannot be converted to Array",
inspect_type(mrb, ary));
}
return ary;
}
MRB_API mrb_value
mrb_check_array_type(mrb_state *mrb, mrb_value ary)
{
if (!mrb_array_p(ary)) return mrb_nil_value();
return ary;
}
MRB_API mrb_value
mrb_inspect(mrb_state *mrb, mrb_value obj)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment