austenmadden / raze

Ruby Gem to flatten nested collections into one dimensional representations.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Raze

Ruby Gem to flatten nested collections into one dimensional representations.

https://rubygems.org/gems/raze

##Examples

test = {test1: ['test_string', :test_symbol], test2: {test_hash: ['test_string']}}

Raze.flatten(test)
=> [:test1, "test_string", :test_symbol, :test2, :test_hash, "test_string"]

You might be wondering how the flatten method above differs from flatten methods in array or hash ruby core libraries. Unfortunately on their own the core methods won't flatten values/recurse through hashes.

irb(main):010:0> a = {test1: ['test_string', :test_symbol], test2: {test_hash: ['test_string']}}
=> {:test1=>["test_string", :test_symbol], :test2=>{:test_hash=>["test_string"]}}
irb(main):011:0> a.flatten(30)
=> [:test1, "test_string", :test_symbol, :test2, {:test_hash=>["test_string"]}]

About

Ruby Gem to flatten nested collections into one dimensional representations.

License:MIT License


Languages

Language:Ruby 100.0%