在哈希,我可以使用我可以为Ruby的MatchData设置默认值吗?
map = Hash.new("(0,0)")
或
map = Hash.new()
map.default = "(0, 0)"
设置为未定义键的默认值,这样,当我尝试检索未定义键的值,我不会得到一个错误。但在MatchData中,例如:
line = "matchBegins\/blabla\" = (20, 10);"
get = line.match(/matchBegins\/(?<match1>\D*)" *= *(?<match2>.*);/)
puts get[:notExisted]
我会收到一个错误。我检查过MatchData的文档,但不能设置任何设置默认值。我对么?由于
你是指'(?P \ D *)'? –