为什么正则表达式不能用于收集

时间:2021-12-14 21:43:58

So trying to run this on the model HomeLoan and gives me a bug:

所以试图在HomeLoan模型上运行它并给我一个bug:

HomeLoan.columns.collect {|x| p /month/.match(x.name.to_s)}
SyntaxError: (irb):30: syntax error, unexpected '.'
HomeLoan.columns.collect {|x| p /month/.match(x.name.to_s)}
                                        ^

???

However when I run:

但是,当我跑:

/month/.match("month") succeeds....

Slightly confused in here. Any help would be appreciated.

在这里有点困惑。任何帮助,将不胜感激。

1 个解决方案

#1


1  

What about:

HomeLoan.columns.collect {|x| /month/.match(x.name.to_s)}

#1


1  

What about:

HomeLoan.columns.collect {|x| /month/.match(x.name.to_s)}