Squeel评估字符串作为连接的关键路径

编程入门 行业动态 更新时间:2024-10-18 08:38:15
本文介绍了Squeel评估字符串作为连接的关键路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这里是我真正想做的:

Outage.joins{eval "unit.plant"}

我会有一个字符串,代表 。

但这里是我得到的一个错误:

But here's what I get as an error:

#<Class:0x639e328>: unknown class: Squeel::Nodes::Function

我试过:

Outage.joins{"unit.plant"}

但这不行...我失踪了什么?

But that does not work... what am I missing?

我在github页面上看不到任何文档: github/ ernie / squeel /

I don't see any documentation on this on the github page: github/ernie/squeel/

感谢您的帮助!

更新: 我发现一个真正令人困惑的方法来解决这个问题:

Update: I've found a really confusing way to pull this off:

("unit.plant".split ".").map{ |x| x.to_sym }.reverse.inject{ |acc, x| { x => acc } }

这将输出:

{:unit=>:plant}

被传递到连接squeel函数。我确定有一个比建立嵌套符号更好的方法:(

This can be passed into the joins squeel function. I'm sure there has to be a better way than to construct nested symbols :(

推荐答案

Outage.joins{Squeel::Nodes::KeyPath.new("unit.plant".split("."))}

资料来源: KeyPath文档

更多推荐

Squeel评估字符串作为连接的关键路径

本文发布于:2023-10-23 05:36:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519947.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   路径   关键   Squeel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!