class Instructions < Array def process return self.to_enum unless block_given? self.each do |instruction| yield(instruction) end end end instructions = Instructions.new(%I(instruction1 instruction2)) instructions.process { |instruction| pp instruction } # => list instructions instructions.process # => #<Enumerator: ...>
class Instructions < Array def process(&block) = self.each(&block) end instructions = Instructions.new(%I(instruction1 instruction2)) instructions.process { |instruction| pp instruction } # => list instructions instructions.process # => #<Enumerator: ...>