我在a third-party project上做了一些工作。该self.configure
块是巨大的,并且包含了一些with
语句,例如:神秘的红宝石语法(带“字符串”)
def self.configure
with 'ead' do |node|
make :resource
end
ignore 'titlepage'
with 'archdesc' do
# etc
这看起来像某种方式建立在方法的参数部分switch语句,但我从来没见过这种语法。这里的任何人都知道发生了什么事?
这是一个DSL。 https://en.wikipedia.org/wiki/Domain-specific_language非常常见。见Rspec。 – Ryanmt