首页 文章

如何在宏中使用正则表达式?

提问于
浏览
1
{% nilable = /\:\:Nil|\?$/.match(type) %}

它似乎不起作用: undefined macro method 'RegexLiteral#match' .

1 回答

  • 3

    Macros::StringLiteral=~ 实例:

    {% type = "Module::Nil" %}
    {% p type =~ /\:\:Nil|\?$/ %} #=> true
    
    {% type = "Module::Null" %}
    {% p type =~ /\:\:Nil|\?$/ %} #=> false
    

相关问题