no one uses Array.try_convert, so removed it that discourages duck typing; close #2317

parent 229e7fe2
......@@ -3,35 +3,6 @@
#include "mruby/array.h"
#include "mruby/range.h"
/*
* call-seq:
* Array.try_convert(obj) -> array or nil
*
* Try to convert <i>obj</i> into an array, using +to_ary+ method.
* Returns converted array or +nil+ if <i>obj</i> cannot be converted
* for any reason. This method can be used to check if an argument is an
* array.
*
* Array.try_convert([1]) #=> [1]
* Array.try_convert("1") #=> nil
*
* if tmp = Array.try_convert(arg)
* # the argument is an array
* elsif tmp = String.try_convert(arg)
* # the argument is a string
* end
*
*/
static mrb_value
mrb_ary_s_try_convert(mrb_state *mrb, mrb_value self)
{
mrb_value ary;
mrb_get_args(mrb, "o", &ary);
return mrb_check_array_type(mrb, ary);
}
/*
* call-seq:
* ary.assoc(obj) -> new_ary or nil
......@@ -139,8 +110,6 @@ mrb_mruby_array_ext_gem_init(mrb_state* mrb)
{
struct RClass * a = mrb->array_class;
mrb_define_class_method(mrb, a, "try_convert", mrb_ary_s_try_convert, MRB_ARGS_REQ(1));
mrb_define_method(mrb, a, "assoc", mrb_ary_assoc, MRB_ARGS_REQ(1));
mrb_define_method(mrb, a, "at", mrb_ary_at, MRB_ARGS_REQ(1));
mrb_define_method(mrb, a, "rassoc", mrb_ary_rassoc, MRB_ARGS_REQ(1));
......
##
# Array(Ext) Test
assert("Array::try_convert") do
assert_equal [1], Array.try_convert([1])
assert_nil Array.try_convert("1")
end
assert("Array#assoc") do
s1 = [ "colors", "red", "blue", "green" ]
s2 = [ "letters", "a", "b", "c" ]
......
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