Created
June 13, 2013 19:18
-
-
Save Benjmin/5776528 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| once_a_day(:thursday) do | |
| puts 'hello' | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Loop | |
| def initialize | |
| @all = {} | |
| @once = {} | |
| @today = lambda {|date| Time.now.send("#{date}?")} | |
| @count = 0 | |
| end | |
| def defmeth( list , date , &block ) | |
| code = { date => block} | |
| list.merge!(code) | |
| end | |
| def once_a_day(date, &block) | |
| defmeth(@once,date,&block) | |
| instance_variable_set("@accomplished#{@count}",false) | |
| @count += 1 | |
| end | |
| def all_day(date, &block) | |
| defmeth(@all,date,&block) | |
| end | |
| def execute | |
| loop do | |
| "all:" | |
| @all.each do |key,value| | |
| while @today.call(key) | |
| value.call | |
| end | |
| end | |
| @once.each do |key,value| | |
| @once.to_a.each_index do |i| | |
| unless instance_variable_get("@accomplished#{i}") | |
| if @today.call(key) | |
| value.call | |
| instance_variable_set("@accomplished#{i}",true) | |
| else | |
| instance_variable_set("@accomplished#{i}",false) | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| looop = Loop.new | |
| Dir.glob("*.roop.rb").each do |file| | |
| irb looop | |
| looop.instance_eval do | |
| load file | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| loop.roop.rb:1:in `<top (required)>': undefined method `once_a_day' for main:Object (NoMethodError) | |
| from looper.rb:50:in `load' | |
| from looper.rb:50:in `block (2 levels) in <main>' | |
| from looper.rb:49:in `instance_eval' | |
| from looper.rb:49:in `block in <main>' | |
| from looper.rb:48:in `each' | |
| from looper.rb:48:in `<main>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment