Skip to content

SINTEF-9012/Rodash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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