Removed `try_convert` method from Array and Hash.
MODIFY
mrbgems/mruby-array-ext/mrblib/array.rb
mrbgems/mruby-array-ext/mrblib/array.rb
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

MODIFY
mrbgems/mruby-array-ext/test/array.rb
mrbgems/mruby-array-ext/test/array.rb
##
# 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" ]

MODIFY
mrbgems/mruby-hash-ext/mrblib/hash.rb
mrbgems/mruby-hash-ext/mrblib/hash.rb
@@ -60,25 +60,6 @@ class Hash
h
end
- ##
- # call-seq:
- # Hash.try_convert(obj) -> hash or nil
- #
- # Try to convert <i>obj</i> into a hash, using to_hash method.
- # Returns converted hash or nil if <i>obj</i> cannot be converted
- # for any reason.
- #
- # Hash.try_convert({1=>2}) # => {1=>2}
- # Hash.try_convert("1=>2") # => nil
- #
- def self.try_convert(obj)
- if obj.respond_to?(:to_hash)
- obj.to_hash
- else
- nil
- end
- end
-
##
# call-seq:
# hsh.merge!(other_hash) -> hsh

MODIFY
mrbgems/mruby-hash-ext/test/hash.rb
mrbgems/mruby-hash-ext/test/hash.rb
@@ -45,12 +45,6 @@ assert('Hash.[] for sub class') do
assert_equal(sub_hash_class, sub_hash.class)
end
-assert('Hash.try_convert') do
- assert_nil Hash.try_convert(nil)
- assert_nil Hash.try_convert("{1=>2}")
- assert_equal({1=>2}, Hash.try_convert({1=>2}))
-end
-
assert('Hash#merge!') do
a = { 'abc_key' => 'abc_value', 'cba_key' => 'cba_value' }
b = { 'cba_key' => 'XXX', 'xyz_key' => 'xyz_value' }

Removed `try_convert` method from Array and Hash.