Skip to content

Latest commit

 

History

History
12 lines (8 loc) · 326 Bytes

as_question.md

File metadata and controls

12 lines (8 loc) · 326 Bytes

as?

The as? pseudo-method is similar to as, except that it returns nil instead of raising an exception when the type doesn't match. It also can't be used to cast between pointer types and other types.

Example:

value = rand < 0.5 ? -3 : nil
result = value.as?(Int32) || 10

value.as?(Int32).try &.abs