concept _ * method in category ruby

appears as: _* methods
The Well-Grounded Rubyist, Third Edition

This is an excerpt from Manning's book The Well-Grounded Rubyist, Third Edition.

Getting back to the to_* family of converters: in addition to the straightforward object-conversion methods, Ruby gives you a couple of to_* methods that have a little extra intelligence about what their value is expected to do.

Like to_str, to_ary provides a way for an object to step into the role of an object of a particular core class. As is usual in Ruby, sensible usage of conventions is left up to you. It’s possible to write a to_ary method, for example, that does something other than return an array—but you’ll almost certainly get an error message when you try to use it, as Ruby looks to to_ary for an array. So if you’re going to use the role-playing to_* methods, be sure to play in Ruby’s ballpark.