Skip to content

Commit

Permalink
Add MergeInitializer to Coercian example
Browse files Browse the repository at this point in the history
Before:
```ruby
class Tweet < Hash
  include Hashie::Extensions::Coercion
  coerce_key :user, User
end

user_hash = { name: "Bob" }
Tweet.new(user: user_hash)
# => {}
```

After:
```ruby
class Tweet < Hash
  include Hashie::Extensions::Coercion
  include Hashie::Extensions::MergeInitializer
  coerce_key :user, User
end

user_hash = { name: "Bob" }
Tweet.new(user: user_hash)
#=> {:user=>#<struct User name={:name=>"Bob"}>}
```
  • Loading branch information
boffbowsh committed Dec 1, 2016
1 parent e35e628 commit faa728e
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -44,6 +44,7 @@ Coercions allow you to set up "coercion rules" based either on the key or the va
```ruby
class Tweet < Hash
include Hashie::Extensions::Coercion
include Hashie::Extensions::MergeInitializer
coerce_key :user, User
end

Expand Down

0 comments on commit faa728e

Please sign in to comment.