Flowdock
def_array_element(name, plural=nil, klass_name=nil) public

No documentation

This method has no description. You can help the Ruby community by adding new notes.

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
Register or log in to add new notes.