This gem let you quickly access and update nested Hash and List structures using a dot notation string.
{ a: [ 100, 200 ] }.access("a.0")
=> 100
{ a: { b: 100 } }.access("a.b")
=> 100
{'availableForPickup': false}.access(:availableForPickup)
=> false
h = { a: { "b"=> 10 } }
h.set("a.b", 2)
=> { a: { "b"=> 2 } }
h.set("a.b1.0", 10)
=> { a: { "b"=> 2, b1: [10] } }
h.set("a.b.c", 100)
=> { a: { "b"=> {c: 100}, b1: [10] } }
h = { phone_numbers: [ { type: "mobile", num: 123 } ] }
h.set("phone_numbers.0.type", "fixed")
There is also a method for segmentation.
[1,2,3,4].segmentation(2)
=> [[[1], [2, 3, 4]],
[[1, 2], [3, 4]],
[[1, 2, 3], [4]]]
gem install vine
require "vine"