safe-navigation-operator Questions
5
Solved
Question:
Does Ruby safe navigation operator (&.) evaluate its parameters when its receiver is nil?
For example:
logger&.log("Something important happened...")
Is the "Some...
Fauteuil asked 21/7, 2020 at 20:9
7
h = {
data: {
user: {
value: "John Doe"
}
}
}
To assign value to the nested hash, we can use
h[:data][:user][:value] = "Bob"
However if any part in the middle is missing, it will cause e...
Arsonist asked 5/1, 2016 at 20:16
3
Solved
As Ruby 2.3 introduces the Safe navigation operator(&.), a.k.a lonely operator, the behavior on nil object seems odd.
nil.nil? # => true
nil&.nil? # => nil
Is that designed to beha...
Advisory asked 4/1, 2016 at 0:15
22
Solved
I'll explain by example:
Elvis Operator (?: )
The "Elvis operator" is a shortening
of Java's ternary operator. One
instance of where this is handy is for
returning a 'sensible default' value...
Mainis asked 7/7, 2011 at 16:30
4
Solved
I have used Safe Navigation Operator for Objects to load on Asynchronous calls and it is pretty amazing. I thought I could reproduce the same for Arrays but it displays a template parse error in my...
Dragonfly asked 20/6, 2017 at 7:31
2
The answers to every question I can find (Q1, Q2) regarding Ruby's new safe navigation operator (&.) wrongly declare that obj&.foo is equivalent to obj && obj.foo.
It's easy to dem...
Showboat asked 4/1, 2016 at 23:59
1
Solved
Ruby 2.3.0 introduces the safe navigation syntax that eases the nil handling of chained method calls by introducing a new operator that only calls the method if value of previous statement is not n...
Gian asked 16/11, 2015 at 12:19
1
© 2022 - 2024 — McMap. All rights reserved.