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 40
        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}              #{name} = self.class::#{klass_name}.new(@maker)              @#{plural} << #{name}              if block_given?                yield #{name}              else                #{name}              end            end            alias new_child new_#{name}            def to_feed(*args)              @#{plural}.each do |#{name}|                #{name}.to_feed(*args)              end            end            def replace(elements)              @#{plural}.replace(elements.to_a)            end, __FILE__, __LINE__ + 1)
        end
Register or log in to add new notes.