Instantly share code, notes, and snippets.

Embed
What would you like to do?
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