No commit activity in last 3 years
No release in over 3 years
Like recursive-open-struct but slightly different
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.6
~> 10.0
>= 3

Runtime

 Project Readme

SuperRecursiveOpenStruct

Build Status Dependency Status Code Climate Gem Version

SuperRecursiveOpenStruct is similar to RecursiveOpenStruct but with these two differences:

  • it supports arrays (either at the top level or nested within a hash)
  • it raises NoMethodError instead of returning nil when accessing an undefined hash key (can be disabled by passing raise_on_missing_methods: false to #initialize)

Usage

require "super_recursive_open_struct"

sros = SuperRecursiveOpenStruct.new(a: {b: 1})
sros.a.b #=> 1
sros.z #=> NoMethodError: undefined method `z' for #<SuperRecursiveOpenStruct:0x489e1e0 a={:b=>1}>

sros_with_array = SuperRecursiveOpenStruct.new(a: [1, 2, 3])
sros_with_array.a #=> [1, 2, 3]
sros_with_array.a.last #=> 3

SuperRecursiveOpenStruct.new({a: 1}, raise_on_missing_methods: false).z #=> nil

License

MIT