An open API service indexing awesome lists of open source software.

https://github.com/styd/sleep2

Ruby sleep 😴 with extra magical stuff.
https://github.com/styd/sleep2

gem ruby sleep

Last synced: about 21 hours ago
JSON representation

Ruby sleep 😴 with extra magical stuff.

Awesome Lists containing this project

README

        

# Sleep2 [![Build Status](https://travis-ci.org/styd/sleep2.svg?branch=master)](https://travis-ci.org/styd/sleep2)

Ruby sleep with extra magical stuff. These extra stuff will be useful when you
are developing an algorithm with some kind of delay patterns such as in
animation.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'sleep2'
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install sleep2

## Usage

Don't forget to `require 'sleep2'` first.

### Do math with sleep.

```ruby
>> sleep = Sleep2[2] # no sleep when instantiating
#=> #
>> sleep # sleeps for 2 seconds
#=> #
>> delay = sleep * 2 # instantiate new sleep object (therefore no sleeping yet)
#=> #
>> delay # sleeps twice longer than sleep
#=> #
```

### Compare sleep with integer (in seconds) or another of its type

```ruby
>> sleep if sleep > 3 # not sleeping at all since sleep duration is 2 seconds
#=> nil
>> delay = Sleep2[3] # no sleep when instantiating
#=> #
>> delay > sleep ? delay : sleep # sleeps for 3 seconds
#=> #
```

### Change current instance duration

```ruby
>> freeze = Sleep2[3] # no sleep when instantiating
#=> #
>> freeze[4] # no sleep when changing duration
#=> 4.0
>> freeze # sleeps for 4 seconds
#=> #
```

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/styd/sleep2. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.

## License

The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).