神秘红宝石语法(用“字符串”做)

时间:2015-09-25 17:49:30

标签: ruby

我正在a third-party project做一些工作。 self.configure块很大,包含许多with语句,例如:

def self.configure

    with 'ead' do |node|
        make :resource
    end

    ignore 'titlepage'

    with 'archdesc' do 
        # etc

这看起来像是以某种方式构建到方法的参数部分中的switch语句,但我以前从未见过这种语法。这里的任何人都知道发生了什么事吗?

2 个答案:

答案 0 :(得分:1)

它只是一个采用字符串和块的方法:

https://github.com/archivesspace/archivesspace/blob/fb860a81f70a98eb489564b6e17d2c120c40fc5f/backend/app/converters/lib/xml_sax.rb#L25

它定义了XML标记处理程序:

def with(path, &block)
  define_method(handler_name(path), block)
end

答案 1 :(得分:0)

这是一种将"ead"作为参数和块的方法。