🖥

I understand #Ruby Lonely operator &. is a operator allows nil receive

2020/01/10に公開

If receiver is nil you can do method chains many times

nil&.to_wow
# => nil
nil&.to_wow&.to_ya
# => nil
nil&.to_wow&.to_ya&.to_yes!
# => nil

If not nil is reciever then you can not chain undefined method by lonely operator

100&.to_wow
NoMethodError: undefined method `to_wow' for 100:Integer

Original by Github issue

https://github.com/YumaInaura/YumaInaura/issues/2924

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2020-01-10

Discussion