public
anonymous / block_woes_ref2
Created

  • Download Gist
block_woes_ref2
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 55 56
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.