https://github.com/sintef-9012/rodash
_.set, _.get, and _.unset for Ruby
https://github.com/sintef-9012/rodash
gem lodash ruby
Last synced: 9 months ago
JSON representation
_.set, _.get, and _.unset for Ruby
- Host: GitHub
- URL: https://github.com/sintef-9012/rodash
- Owner: SINTEF-9012
- License: mit
- Created: 2016-02-23T14:40:46.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2024-01-24T11:24:28.000Z (over 2 years ago)
- Last Synced: 2025-07-22T12:18:31.416Z (9 months ago)
- Topics: gem, lodash, ruby
- Language: Ruby
- Homepage: https://rubygems.org/gems/rodash
- Size: 20.5 KB
- Stars: 10
- Watchers: 14
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rodash
[_.set](https://lodash.com/docs#set), [_.get](https://lodash.com/docs#get), and [_.unset](https://lodash.com/docs#unset) for Ruby
The two methods set and get are based on [Lodash](https://lodash.com/) and ported to Ruby, along with their unit tests.
## Install
`gem install rodash`
### Rodash.set example
```ruby
object = { 'a' => [{ 'b' => { 'c' => 3 } }] }
Rodash.set(object, 'a[0].b.c', 4)
object['a'][0]['b']['c']
=> 4
Rodash.set(object, 'x[0].y.z', 5)
object['x'][0]['y']['z'])
=> 5
```
### Rodash.get example
```ruby
object = { 'a' => [{ 'b' => { 'c' => 3 } }] }
Rodash.get(object, 'a[0].b.c')
=> 3
Rodash.get(object, ['a', '0', 'b', 'c'])
=> 3
Rodash.get(object, 'a.b.c', 'default')
=> 'default'
```
### Rodash.unset example
```ruby
object = { 'a' => [{ 'b' => { 'c' => 7 } }] }
Rodash.unset(object, 'a[0].b.c')
=> true
object
=> { 'a' => [{ 'b' => {} }] }
Rodash.unset(object, 'a[0].b.c')
=> true
object
=> { 'a' => [{ 'b' => {} }] }
```