Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created November 23, 2010 04:05
Show Gist options
  • Select an option

  • Save JoshCheek/711222 to your computer and use it in GitHub Desktop.

Select an option

Save JoshCheek/711222 to your computer and use it in GitHub Desktop.
shows very simplified version of how I implemented my itinerary
module Itinerary
class Day
def initialize(date,&block)
@date = date
instance_eval(&block)
end
def readings
@readings ||= Array.new
end
def read(title)
readings << Read.new(title)
end
def to_s
@date
end
end
class Read
def initialize(title)
@title = title
end
def to_s
@title
end
end
module Output
def self.output(days)
days.map do |day|
[ day ,
day.readings.map { |reading| " #{reading}" }
]
end.flatten.join("\n")
end
end
def self.output
Output.output days
end
def self.by(date,&block)
days << Day.new( date , &block )
end
def self.days
@days ||= Array.new
end
end
def by(date,&block)
Itinerary.by(date,&block)
end
by 'Monday' do
read 'page 1'
read 'page 2'
end
by 'Tuesday' do
read 'page 3'
read 'page 4'
end
puts Itinerary.output
# >> Monday
# >> page 1
# >> page 2
# >> Tuesday
# >> page 3
# >> page 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment