我很茫然。希望有更多Ruby经验的人会告诉我发生了什么。
我正在从样式表调用自定义Sass函数,如下所示:
$color: user_var('color')
自定义函数如下所示:
module Sass::Script::Functions
def user_var(param_name)
puts options[:custom]
puts options[:custom].fetch('color')
puts options[:custom].fetch(param_name)
end
end
puts options[:custom]
(正如预期的那样)的结果是:
{"color"=>#eeeeee, "header"=>20px}
puts options[:custom].fetch('color')
的结果是#eeeeee
但是...... puts options[:custom].fetch(param_name)
的结果会导致“找不到关键字:'颜色'(KeyError)”。
完全不知道在这里。
答案 0 :(得分:0)
我的猜测是param_name是一个符号,选项哈希中的颜色键被定义为一个字符串。
这应该有效。
options[:custom].fetch("#{param_name}")