to_ary is Ruby’s implicit array-conversion method. It lets an object play the role of an Array when an operation requires an array specifically, rather than merely something that can be converted generally. section 7.4.4
Making a Person behave like an array
A Person object can expose selected attributes as an array: `def to_ary; [name, age, email]; end`. After `array = []`, calling `array.concat(person)` adds the person’s name, age, and email values to the target array.
Keep to_ary distinct from broader array construction:
- `Array(obj)` calls `to_ary` first, then tries `to_a`; without either method, it wraps the object in a one-element array. section 9.2.1
- Use the convention carefully: to_ary should provide a sensible array-compatible representation, not an unrelated value. section 7.4.4
