DEV Community

Burdette Lamar
Burdette Lamar

Posted on

4

Convertible Objects

Little-known fact: Many Ruby methods accept as arguments not only an instance of a class (e.g., Array object), but also an object that can be converted to that class (e.g., Array-convertible object).

This is true of a dozen or so methods in Hash, and of scores of methods in Array. How many others? I don't know (yet).

There are even a few methods that accept a convertible object as a block return value. Check out method Array#max.

Obscure, I know, but interesting.

Read all about it: Class-Convertible Objects.

Top comments (1)

Collapse
 
kwstannard profile image
Kelly Stannard β€’

Nice.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay