Discussion
Loading...

Post

Log in
  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
Henrik Nyh
@henrik@ruby.social  ·  activity timestamp 4 weeks ago
#Ruby pattern matching for optional types of sorts:

```
def user_name(maybe_user)
case maybe_user
in User => user then user.full_name
in nil then nil
end
end
```

And:

```
def user_name!(maybe_user)
case maybe_user
in User => user then user.full_name
# No else – raises if not User.
end
end
```

  • Copy link
  • Flag this post
  • Block
Log in

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.0-rc.2.6 no JS en
Automatic federation enabled
  • Explore
  • About
  • Members
  • Code of Conduct