mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Removed try_convert method from Array and Hash.
This commit is contained in:
@@ -1,29 +1,4 @@
|
||||
class Array
|
||||
##
|
||||
# call-seq:
|
||||
# Array.try_convert(obj) -> array or nil
|
||||
#
|
||||
# Tries to convert +obj+ into an array, using +to_ary+ method.
|
||||
# converted array or +nil+ if +obj+ 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
|
||||
#
|
||||
def self.try_convert(obj)
|
||||
if obj.respond_to?(:to_ary)
|
||||
obj.to_ary
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# call-seq:
|
||||
# ary.uniq! -> ary or nil
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
##
|
||||
# Array(Ext) Test
|
||||
|
||||
assert("Array.try_convert") do
|
||||
assert_nil Array.try_convert(0)
|
||||
assert_nil Array.try_convert(nil)
|
||||
assert_equal [], Array.try_convert([])
|
||||
assert_equal [1,2,3], Array.try_convert([1,2,3])
|
||||
end
|
||||
|
||||
assert("Array#assoc") do
|
||||
s1 = [ "colors", "red", "blue", "green" ]
|
||||
s2 = [ "letters", "a", "b", "c" ]
|
||||
|
||||
Reference in New Issue
Block a user