Skip to content

Instantly share code, notes, and snippets.

@nanosplit
Created April 30, 2018 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanosplit/924f2619d95ce1c5735a8e3f6f2904b7 to your computer and use it in GitHub Desktop.
Save nanosplit/924f2619d95ce1c5735a8e3f6f2904b7 to your computer and use it in GitHub Desktop.
def arrayify(string)
if string.class == Array
string.to_a.map{ |v1|
if v1.class == Array
v1.map{ |v2|
if v2.class == Symbol
v2
elsif v2.class == Array
v2.map{|k|
if k.class == Hash
k.map{|k,v| {k => arrayify(v)}}
else
k.strip
end
}
elsif v2.class == Hash
v2.map{ |key,value|
if value.class == Array || value.class == Hash
{key => arrayify(value)}
else
{key => value.strip}
end
}
else
v2.strip
end
}
elsif v1.class == Hash
v1.map{|k,v| {k => arrayify(v)}}
else
v1.split(',').join(',').split(',').map(&:strip)
end
}.flatten
elsif string.class == Hash
string.map{|k,v|
{k => arrayify(v)}
}
else
string.split(',').join(',').split(',').map(&:strip)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment