Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the meaning of :[]

I'm new to ruby on rails, there's a code something like:

person_map.try(:[], :name)

What's the meanning of :[] here?

like image 456
hongchangfirst Avatar asked Jul 20 '19 17:07

hongchangfirst


People also ask

What is the meaning of Lnade?

1 : a narrow passageway between fences or hedges. 2 : a relatively narrow way or track: such as. a : an ocean route used by or prescribed for ships. b : a strip of roadway for a single line of vehicles. c : air lane.

What is the meaning of Sinuating?

to curve or wind in and out; creep in a winding path. a snake sinuating along the ground.

What is the meaning of Ywide?

1 : having a large measure across : broad a wide street a wide grin. 2 : opened as far as possible Her eyes were wide with wonder. 3 : covering a very large area a wide expanse of ocean. 4 : measured across or at right angles to length The cloth is three feet wide.

What is the meaning of Moanings?

to make a long, low sound of pain, suffering, or another strong emotion: He moaned with pain before losing consciousness. "Let me die," he moaned. SMART Vocabulary: related words and phrases.


1 Answers

:[] is a symbol. In the context of your line of code, it represents the name of the method which should be tryed.

You should check the documentation of try to better understand that line of code. It's basically equal to personMap[:name] while making sure that no exception will be raised if personMap does not have a [] method (e.g if personMap is nil).

like image 113
Tamer Shlash Avatar answered Oct 02 '22 16:10

Tamer Shlash