自己yield
RubyのライブラリにNokogiriというのがある。HTMLファイルからタグ情報を取得して解析する。このライブラリは設定をブロックから行うことができる。
doc = Nokogiri::XML(File.open("blossom.xml")) do |config| config.strict.nonet end
Ruby タプログラミング本にも記載があった。ちょいメモ代わりに書いておく。
class My attr_accessor :timeout, :error_message def initialize yield self if block_given? end end parse = My.new do |config| config.timeout = 20 config.error_message = true end puts parse.timeout