Skip to content

Instantly share code, notes, and snippets.

@thonixx
Created July 19, 2016 11:36
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 thonixx/7e71168440f7858c89947184b9b47c2a to your computer and use it in GitHub Desktop.
Save thonixx/7e71168440f7858c89947184b9b47c2a to your computer and use it in GitHub Desktop.
Force Ruby to build an array of of an array-like string
<%
# define things
orig="item0"
orig='["item1", "item2"]'
orig=["item3", "item4"]
# force ruby to make it an array
if ! orig.respond_to?('each')
var=orig.gsub(/(^\[|\]$)/, "").gsub(/\"/, "").gsub(/\ */, "").split(",")
else
var=orig
end
%>
Foo bar:
<%
var.each do |value|
%>Value: <%= value %> SOMETHING
<%
end
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment