Ruby's Array class has the built-in method to_s that can turn the array into a string. This method also works with multidimensional array. How is this method implemented?
I want to know about it, so I can reimplement a method my_to_s(ary) that can take in a multidimensional and turn it to a string. But instead of returning a string representation of the object like this
[[[1,2,3, Person.new('Mary')]],[4,5,6,7], Person.new('Paul'),2,3,8].to_s
# [[[1, 2, 3, #<Person:0x283fec0 @name='Mary']], [4, 5, 6, 7], #<Person:0x283fe30 @name='Paul'>, 2, 3, 8]
my_to_s(ary) should call the to_s method on these objects, so that it returns
my_to_s([[[1,2,3, Person.new('Mary')]],[4,5,6,7], Person.new('Paul'),2,3,8])
# [[[1, 2, 3, Student Mary]], [4, 5, 6, 7], Student Paul>, 2, 3, 8]
Person#to_sto return"Student #{self.name}"string.