0
我目前正在使我的博客與Jekyll。 Jekyll自定義插件使用Ruby和Jekyll使用Liquid。我目前通過定製液體標籤獲得輸入並在那裏處理。我想檢查字符串是否包含整數。所以我有以下代碼。我意識到輸入不是String類型,而是Jekyll :: Token類型。所以我改變了輸入到字符串,但我無法檢測字符串是否包含整數。這裏是我的代碼:類型檢查不適用於紅寶石和液體
module Jekyll
class TypecheckTag < Liquid::Tag
def is_int(word)
return word.count("0-3000") > 0
end
def initialize(tag_name, word, tokens)
super
@word = word.to_s
end
def render(context)
if /\A\d+\z/.match(@word)
@result = 'int'
else
@result = 'string'
end
end
end
end
Liquid::Template.register_tag('typecheck', Jekyll::TypecheckTag)
不幸的是,它總是返回'字符串'即使我們有一個字符串「16」例如。
這不完全是我想要的,但我通過上下文獲取值來解決它。 –