arrays - Converting hash to string in Ruby -
Assume that we have a hash:
flash = {} flash [ Error] = "This is an error." Flash [: info] = "This is a notification."
I would like to convert it to string:
"div class = 'error' & gt; This is an error. & Lt; / div & Gt; & lt; div class = 'info' & gt; This is a notification ".
In a nice liner;)
I found something like this:
flash.to_a.collect {| Item | "& Lt; div class = '# {item} [0]}" gtc: # {item [1]}
This solves my problem but maybe in the hashtable class Made a good solution?
is included so that you can use it:
Flash.collect {| K, v | "& Lt; div class = '# {k}' & gt; # {v} & lt; / div & gt; } .join
Comments
Post a Comment