<div dir="ltr">Hey!<div><br></div><div>Loose "<font color="#212121" face="helvetica neue, helvetica, arial, sans-serif"><span style="line-height:1.5">JSON.pretty_generate" at the and </span>new-lines<span style="line-height:1.5"> will go away.</span></font></div><div><span style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;line-height:1.5"><br></span></div><div><span style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;line-height:1.5">Cheers!</span></div><div><span style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;line-height:1.5"><br></span></div><div><span style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;line-height:1.5">- Oto</span></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jun 8, 2016 at 11:53 PM Jesse Waites <<a href="mailto:jesse.waites@gmail.com">jesse.waites@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Update: I tried it with Tom's pretty generate JSON method and am a little closer - @jsonish is now:<div><br></div><div><span style="color:rgb(51,51,51);font-family:verdana,arial,helvetica,sans-serif;font-size:13px;line-height:18px">@jsonish: "[\n {\n \"key\": 0,\n \"value\": 5\n },\n {\n \"key\": 1,\n \"value\": 3\n },\n {\n \"key\": 2,\n \"value\": 2\n }\n]"</span><br></div><div><span style="color:rgb(51,51,51);font-family:verdana,arial,helvetica,sans-serif;font-size:13px;line-height:18px"><br></span></div><div><span style="color:rgb(51,51,51);font-family:verdana,arial,helvetica,sans-serif;font-size:13px;line-height:18px">So looks like I need to strip the new lines out? Or rather, not put them in in the first place? Its good to know I was close in my solution path. </span></div></div><div class="gmail_extra"></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 8, 2016 at 1:03 PM, John Cinnamond <span dir="ltr"><<a href="mailto:jc@panagile.com" target="_blank">jc@panagile.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><img style="border:none;background:none;width:0;min-height:0" src="https://welovepg.polymail.io/v2/z/a/NTc1ODRlZjcyMjhh/us2rHmsD3TsNgdd9TPWvQekkJkmoPlftRS-U7MLA3nXNcdOBglpQM6GzoEw_FyBdNk0dKV2FcEgCi12gF0VdfJMoh36lNC89fBXnzPe1lbDkilafd0HK_j2UpDCRdwZA3Jtn7U3PfeY9Onzlvmk=.png" alt="" width="0px" height="0px" border="0">As an aside, `map` returns an enumerator if you don’t give it a block, and enumerators have a `with_index` method. So instead of:<div><br></div><div> array.each_with_index.map { |value, idx| … }</div><div><br></div><div>You can say:</div><div><br></div><div> array.map.with_index { |value, idx| … }<br><br><div><div>This only saves you 5 characters, but I think it makes the intent slightly clearer.</div><div><br></div><div style="font-size:10px;color:#7e8f9f"></div></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote"><div dir="ltr">On Wed, 08 Jun 2016 at 17:57 Tom Stuart <u></u> <<a href="mailto:Tom+Stuart+%3Ctom@codon.com%3E" target="_blank">Tom Stuart <u></u></a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p>On 8 Jun 2016, at 14:32, Jesse Waites <<a href="mailto:jesse.waites@gmail.com" target="_blank">jesse.waites@gmail.com</a>> wrote:<br>> def make_jsonish(array)<br>> array.each_with_index do |num, i|<br>> puts "{ key: #{i}, value: #{num}},"<br>> end<br>> end<br><br>This looks pretty close to being right, but you want to return a string by joining all the individual lines, not print them out. For example:<br><br>def make_jsonish(array)<br> array.each_with_index.map { |num, i|<br> "{ key: #{i}, value: #{num}},"<br> }.join("\n")<br>end<br><br>Less significantly, it would be better to rely on Ruby to turn the resulting data structure (including enclosing square brackets) into JSON for you, so that you’re not responsible for the conversion yourself:<br><br>def make_jsonish(array)<br> elements = array.each_with_index.map { |num, i|<br> { key: i, value: num}<br> }<br> JSON.pretty_generate(elements)<br>end<br><br>Cheers,<br>-Tom<br>_______________________________________________<br>Chat mailing list<br><a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a><br>Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" target="_blank">http://lists.lrug.org/pipermail/chat-lrug.org</a><br>Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br>List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br></p><div></div></blockquote></div><br></div></div></div><br>_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a><br>
Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/pipermail/chat-lrug.org</a><br>
Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br>
List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div></div><div class="gmail_extra">-- <br><div data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>Jesse Waites</div><div><a href="http://JesseWaites.com" target="_blank">JesseWaites.com</a></div></div></div></div></div></div>
</div>
_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a><br>
Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/pipermail/chat-lrug.org</a><br>
Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br>
List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
</blockquote></div>