Skip to content

Instantly share code, notes, and snippets.

Created June 28, 2012 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3010784 to your computer and use it in GitHub Desktop.
Save anonymous/3010784 to your computer and use it in GitHub Desktop.
class ActivityLogger
def self.reports
@reports ||= []
end
def self.log(&block)
class_eval &block
end
def self.activity(date, &block)
activity = Activity.new(date)
activity.instance_eval &block
reports << activity
end
def self.report
reports.each do |rep|
puts rep.inspect
end
end
end
class Activity
def initialize(date)
@date = date
@logs = []
end
def eat(&block)
#@logs << Log.new(Eat, &block)
log = Log.new(Eat)
log.instance_eval &block
@logs << log
end
end
class Log
attr_accessor :activity, :duration, :priority
def initialize(activity, &block)
@activity = activity
#yield self
end
end
class Eat; end
ActivityLogger.log do
activity('27-06-2012') do
eat do #|act|
duration = 15
priority = 5
end
end
end
ActivityLogger.report
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment