method
def_array_element
def_array_element(name, plural=nil, klass_name=nil)
public
Hide source
# File lib/rss/maker/base.rb, line 38 def def_array_element(name, plural=nil, klass_name=nil) include Enumerable extend Forwardable plural ||= "#{name}s" klass_name ||= Utils.to_class_name(name) def_delegators("@#{plural}", :<<, :[], :[]=, :first, :last) def_delegators("@#{plural}", :push, :pop, :shift, :unshift) def_delegators("@#{plural}", :each, :size, :empty?, :clear) add_need_initialize_variable(plural, "[]") module_eval("def new_\#{name}\n\#{name} = self.class::\#{klass_name}.new(@maker)\n@\#{plural} << \#{name}\nif block_given?\nyield \#{name}\nelse\n\#{name}\nend\nend\nalias new_child new_\#{name}\n\ndef to_feed(*args)\n@\#{plural}.each do |\#{name}|\n\#{name}.to_feed(*args)\nend\nend\n\ndef replace(elements)\n@\#{plural}.replace(elements.to_a)\nend\n", __FILE__, __LINE__ + 1) end