Sha256: f926df914dacbfc78b118693eec62733124b63c94f4843d8862e80e5893cc95c

Contents?: true

Size: 634 Bytes

Versions: 1

Compression:

Stored size: 634 Bytes

Contents

# MethodDecorators

Python's function decorators for Ruby.

## Installation
`gem install method_decorators`

## Usage

### Using a decorator
Extend MethodDecorators in a class where you want to use them, and then stick `+DecoratorName` before your method declaration to use it.

```ruby
class SlowMath
  extend MethodDecorators

  +Memoized
  def fib(n)
    if n <= 1
      1
    else
      fib(n - 1) * fib(n - 2)
    end
  end
end
```

### Defining a decorator

```ruby
class Transactional < MethodDecorator
  def call(wrapped, *args, &blk)
    ActiveRecord::Base.transaction do
      wrapped.call(*args, &blk)
    end
  end
end
```

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
method_decorators-0.9.0 README.md