# Re: Negative Sleep (#87)

**URL:** <https://www.ruby-forum.com/t/re-negative-sleep-87/98936>\
**Category:** Ruby\
**Created:** [July 19, 2006, 3:44am UTC](https://www.ruby-forum.com/t/re-negative-sleep-87/98936 "2006-07-19T03:44:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![digitalpodcast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/278dde/32.png) [@digitalpodcast](https://www.ruby-forum.com/u/digitalpodcast)\
**Post date:** [July 19, 2006, 3:44am UTC](https://www.ruby-forum.com/t/re-negative-sleep-87/98936/1 "2006-07-19T03:44:55Z")

</div>

Hi,

I am a beginner, so please forgive my newbish skills 🙂  
I just discovered RubyQuiz, I think it is a great idea, and I thought  
about submitting my own solution.  
I haven’t given an alternative interpretation of sleep, I just used the  
first definition I read there.

Maybe you could tell what can I do to make it more ruby-ish ? 🙂

```
class Computation
    def initialize(&computation)
        @comp = []
        @comp << computation
        @rev = 0
    end

    def run
        @comp.each do |runnable|
            if runnable.kind_of? Computation
                runnable.run
            else
                runnable.call
            end
        end
    end

    def +(ref)
        t = self
        ref.instance_eval { add_myself(t) }
        self
    end

    protected
    def add_myself(target)
        ref = self
        target.instance_eval do
            if @rev == 0
                @comp << ref
            else
                @comp.unshift ref
                @rev -= 1
            end
        end
    end
end

class Sleep < Computation
    alias old_init initialize
    alias old_add_myself add_myself
    attr_reader :seconds

    def initialize(seconds)
        old_init do sleep(seconds > 0 ? seconds : -seconds); end
        @seconds = seconds
    end

    protected
    def add_myself(target)
        ref = self
        target.instance_eval do
            @rev = 2 if ref.kind_of? Sleep and ref.seconds < 0
        end
        old_add_myself(target)
    end
end
```
