我正在尝试为ruby创建一个内部dsl,我还没有开始编写它,我想知道这个语法在ruby中是否可行:

IF more_than: 1, :class smells to: "god class", sense: HIGH and has "no temp attributes", sense: 0.5
THEN problem "some problem"
WITH ponderation percent: 10

还有:
IF more_than: 1, :class
{
    smells to: 'god class', sense: 2
    and
    (
        has 'no temp attributes', sense: 0.5 or
        smells to: 'extensive coupling', sense: 1.5 or
        has 'refused parent Bequest', sense: HIGH or
        smells to: 'tradition breaker', sense: LOW
    )
    and
    (
        has :Method
        {
            smells to: 'extensive coupling', sense: 1.5
        }
    )
}
THEN
{
    problem "abusive conceptualization"
}
WITH
{
    ponderation percent: 10
}

更新:
:d我仍然在定义dsl的需求,这是我的起点,我正在考虑自定义解析器或ruby。您认为为它创建一个自定义解析器或使用ruby更好吗?

最佳答案

这是不可能的。问题在于这些结构:

:class to

不能将参数传递给符号,只能传递给方法。

关于ruby - Ruby可以使用这种内部DSL语法吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12890149/

10-11 01:33