Created
July 19, 2016 11:36
-
-
Save thonixx/7e71168440f7858c89947184b9b47c2a to your computer and use it in GitHub Desktop.
Force Ruby to build an array of of an array-like string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
# 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