-1

Suppose I have 2 components which are not linked (by props) A and B. They are linked but by the database, A has a button which allows it to change the database. And I want B to rerender (not all the page) when the database changes, is that possible?

1 Answers1

2

&. is called a safe navigation operator which was introduced in ruby 2.3, it works similar to the try! method and returns nil if the object is nil else returns the attribute value of the object.

object = OpenStruct.new(a: 1)
object&.a
# => 1 

object = nil
object&.a
# => nil 

object.a
# Traceback (most recent call last):
#         1: from (irb):21
# NoMethodError (undefined method `a' for nil:NilClass)

You can see in the above example the difference when we are calling a on an object with and without &. operator.

Refer SO answer for more details on it.

Holger Just
  • 52,918
  • 14
  • 115
  • 123