Create a gist now

Instantly share code, notes, and snippets.

anonymous /block_woes_ref2
Created Jun 28, 2012

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