brianmario/yajl-ruby — pull request #139 by padde (2014-06-19 15:56:31+00:00)
Title: Block parameters for Parser.new and Encoder.new

Just wanted to sprinkle some syntactic sugar on the `Parser` and `Encoder` classes. Whereas now you would have to write

```ruby
parser = Yajl::Parser.new
parser.on_parse_complete = lambda { |hash|
# do something with hash
}
```

and

```ruby
encoder = Yajl::Encoder.new
encoder.on_progress_callback { |str|
# do something with str
}
```

this branch allows you to write

```ruby
parser = Yajl::Parser.new do |hash|
# do something with hash
end
```

and

```ruby
encoder = Yajl::Encoder.new do |str|
# do something with str
end
```

While I was at it, I

* fixed some typos and indentation in the comments
* found and fixed a bug that rendered `on_progress_callback` practically useless

The bug occurs because `Encoder#encode` takes a block parameter which sets `on_progress_callback` in the background. However, later on the block is called directly instead of referring to the `on_progress_callback`. This means that setting `on_progress_callback` before calling `encode` had no effect. This probably went unnoticed because there was no spec for that case but there is now.

Please comment on my branch and even if you don't like the block parameters, consider cherry-picking the other fixes.

Cheers