Skip to content

Latest commit

 

History

History
54 lines (37 loc) · 982 Bytes

README.md

File metadata and controls

54 lines (37 loc) · 982 Bytes

Rodash

_.set, _.get, and _.unset for Ruby

The two methods set and get are based on Lodash and ported to Ruby, along with their unit tests.

Install

gem install rodash

Rodash.set example

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

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

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' => {} }] }