Skip to content

Commit

Permalink
Merge pull request #3 from gangelo/development
Browse files Browse the repository at this point in the history
Update README.md examples
  • Loading branch information
gangelo authored Aug 13, 2022
2 parents 031fe90 + d5021e6 commit de1a292
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ ImmutableStructEx allows you do this in one step:

```ruby
immutable_struct_ex = ImmutableStructEx.new(first: 'John', last: 'Doe', phone: '(201) 230-7281')
immutable_struct_ex.first
immutable_struct_ex.first
#=> 'John'
immutable_struct_ex[:first]
#=> 'John'
immutable_struct_ex.last
immutable_struct_ex.last
#=> 'Doe'
immutable_struct_ex.phone
immutable_struct_ex.phone
#=> '(201) 230-7281'
```
### Immutable
Expand All @@ -60,6 +60,21 @@ immutable_struct_ex.john?
#=> true
```

### Other Examples
```ruby
user = { username: 'username', password: 'password', ssn: '123-70-9182' }
ImmutableStructEx.new(**user) do
REDACT = %i(username password).freeze

def to_h
super.to_h.tap do |h|
REDACT.each { |redact| h[redact] = :redacted }
end
end
end.to_h
#=> {:username=>:redacted, :password=>:redacted, :ssn=>"123-70-9182"}
```

## Installation

Add this line to your application's Gemfile:
Expand Down

0 comments on commit de1a292

Please sign in to comment.