anonymous / block_woes_ref1
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View block_woes_ref1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
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)
@logs << Log.new(Eat) {|l| l.instance_eval &block}
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
Something went wrong with that request. Please try again.