<commit_before># ValueProtocol

Allows passing any object where a block is expected.  
It is inspired by the way Smalltalk deals with the same scenario, making use of the ```#value``` message.

## Motivation

I wrote this gem to avoid having to wrap objects inside lambdas (and thus, avoid repeating code) when working with messages like ```:detect```.

I wanted to turn this:

```ruby
numbers.detect(lambda{ 2 }) { |number| number.even? }
```

Into something like this, reducing the noise introduced by the ```lambda``` part:

```ruby
numbers.detect(2) { |number| number.even? }
```

Also, I wanted to be able to pass any object when an implicit block is expected:

```ruby
# create an instance of a complex condition
even_numbers = EvenNumberConition.new
numbers.select &even_numbers
```

## How does it works?

Basically, it works by implementing ```:call``` (returning ```self```), and implementing ```:to_proc``` (returning a proc that evaluates ```self.call```) in ```Object```.

It sound more complicated than it really is. Take a look at the [implementation](lib/value_protocol/protocol.rb) and [specs](spec/value_protocol_spec.rb)!

## Usage

Just pass any object where a block is expected (respecting the & operator when needed). That's all.  
If you want to implement custom behavior, override the ```:call``` method in your class (remember to respect the signature!).

For most scenarios, you won't need to override ```:to_proc```.

## Feel like reading a blog post?

Check this out! (TODO: add url)

## Installation

Add this line to your application's Gemfile:

    gem 'value_protocol'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install value_protocol

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request<commit_msg>Added link to this Gem's blog post<commit_after># ValueProtocol

Allows passing any object where a block is expected.  
It is inspired by the way Smalltalk deals with the same scenario, making use of the ```#value``` message.

## Motivation

I wrote this gem to avoid having to wrap objects inside lambdas (and thus, avoid repeating code) when working with messages like ```:detect```.

I wanted to turn this:

```ruby
numbers.detect(lambda{ 2 }) { |number| number.even? }
```

Into something like this, reducing the noise introduced by the ```lambda``` part:

```ruby
numbers.detect(2) { |number| number.even? }
```

Also, I wanted to be able to pass any object when an implicit block is expected:

```ruby
# create an instance of a complex condition
even_numbers = EvenNumberConition.new
numbers.select &even_numbers
```

## How does it works?

Basically, it works by implementing ```:call``` (returning ```self```), and implementing ```:to_proc``` (returning a proc that evaluates ```self.call```) in ```Object```.

It sound more complicated than it really is. Take a look at the [implementation](lib/value_protocol/protocol.rb) and [specs](spec/value_protocol_spec.rb)!

## Usage

Just pass any object where a block is expected (respecting the & operator when needed). That's all.  
If you want to implement custom behavior, override the ```:call``` method in your class (remember to respect the signature!).

For most scenarios, you won't need to override ```:to_proc```.

## Feel like reading a blog post?

Check this out! [Rock Your Ruby: The Value of Value](http://www.10pines.com/blog/posts/rock-your-ruby-the-value-of-value)

## Installation

Add this line to your application's Gemfile:

    gem 'value_protocol'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install value_protocol

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
{'fraction_non_alphanumeric': 0.11066699975018736, 'fraction_numerical': 0.003997002248313765, 'mean_word_length': 4.469945355191257, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '390723', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1120, 'n_words': 533}