Sha256: 324ea01991b401b56f6145beccc39ced8f427d891a1958b7b7aa9f3374c0c4a2
Contents?: true
Size: 833 Bytes
Versions: 11
Compression:
Stored size: 833 Bytes
Contents
module Taskinator class Tasks include Enumerable # implements a linked list, where each task references the next task attr_reader :head alias_method :first, :head def initialize(first=nil) @head = first end def add(task) if @head.nil? @head = task else current = @head while current.next current = current.next end current.next = task end task end alias_method :<<, :add alias_method :push, :add def empty? @head.nil? end def each(&block) return to_enum(__method__) unless block_given? current = @head while current yield current current = current.next end end def inspect %([#{collect(&:inspect).join(', ')}]) end end end
Version data entries
11 entries across 11 versions & 1 rubygems