In crystal Why do I need to do matches.try &.[0]
up vote
0
down vote
favorite
Here's some code: matches = //([a-z]+)/(d+)/state/([a-z]+)/.match(address) # line 1 puts matches[0]? # line 2 puts matches.try &.[0] # line 3 matches datatype is (Regex::MatchData | Nil) according to typeof . Yet, line 2, referring to matches[0] fails with a compilation error. And I don't understand line 3 at all! Could someone clarify?
crystal-lang
share | improve this question
edited Nov 20 at 4:49
Cœur
17.2k 9 102 141