<div><div dir="auto">I think the approach of including a module in Hash is really nice when you get started with a small project. </div><div dir="auto">It allows writing concise code and keeps you focused on the core problem.</div><div dir="auto">But as project sizes increase, having gems that alter core classes becomes less desirable.</div><div dir="auto">New team members still have to read about and understand the new method first.</div><div dir="auto">Occasionally adding modules or monkey patching core classes results in obscure bugs.</div><div dir="auto">E.g. You could imagine a scenario where another developer adds the same method, and load order would determine which method is executed. </div><div dir="auto">So as a general principle it's nice to make monkey patching optional.</div><div dir="auto">Something like:</div><div dir="auto">require "dig_and_collect/core_extension" or </div><div dir="auto">require "dig_and_collect/monkey_patch" would be nice.</div><div dir="auto">Then it can be an opt in for those that want it.</div><div dir="auto">Also to make it useful for those without the monkey patching it would need to be invokable via a method call from outside of a Hash.</div><div dir="auto">E.g. </div><div dir="auto">DigAndCollect.call(hash, *args)</div><div dir="auto"><br></div><div dir="auto"><br></div><br><div class="gmail_quote"><div>On Sat, 21 Oct 2017 at 09:06, Alfredo Motta <<a href="mailto:motta.lrd@hotmail.it">motta.lrd@hotmail.it</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div>
<span style="color:rgb(49,49,49);word-spacing:1px;background-color:rgb(255,255,255)">Hello Rubyist, I am new here and looking forward to talk Ruby!</span>
<div style="color:rgb(49,49,49);word-spacing:1px"><br>
</div>
<div style="color:rgb(49,49,49);word-spacing:1px">I wrote this gem a while ago to make my job of collecting data from deeply nested hashes easier (i.e. the kind of hashes you might get back from the savon gem for example because they represent some underlying
 XML)</div>
<div style="color:rgb(49,49,49);word-spacing:1px"><br>
</div>
<div style="color:rgb(49,49,49);word-spacing:1px">Do you have any feedback on it?</div>
<div style="color:rgb(49,49,49);word-spacing:1px"><a href="https://github.com/mottalrd/hash_dig_and_collect" target="_blank">https://github.com/mottalrd/hash_dig_and_collect</a><br>
</div>
<div style="color:rgb(49,49,49);word-spacing:1px"><br>
</div>
<div style="color:rgb(49,49,49);word-spacing:1px">I wrote about the rationale here</div>
<div style="color:rgb(49,49,49);word-spacing:1px"><a href="http://www.alfredo.motta.name/making-ruby-hashdig-even-more-awesome-introducing-hashdig_and_collect/" target="_blank">http://www.alfredo.motta.name/making-ruby-hashdig-even-more-awesome-introducing-hashdig_and_collect/</a><br>
</div>
<div style="color:rgb(49,49,49);word-spacing:1px"><br>
</div>
<div style="color:rgb(49,49,49);word-spacing:1px">Here is an example where I want the latitude of all the addresses of a given client.</div>
<div style="color:rgb(49,49,49);word-spacing:1px">Thank you for your help, </div>
<div style="color:rgb(49,49,49);word-spacing:1px">Happy weekend </div>
<div style="color:rgb(49,49,49);word-spacing:1px"><br>
</div>
<div style="color:rgb(49,49,49);word-spacing:1px">
<pre style="white-space:pre-wrap;box-sizing:border-box;font-family:SFMono-Regular,Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:16px;word-wrap:normal;padding:16px;overflow:auto;line-height:1.45;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;color:rgb(36,41,46)"><pre style="white-space:pre-wrap;box-sizing:border-box;font-family:SFMono-Regular,Consolas,'Liberation Mono',Menlo,Courier,monospace;margin-top:0px;margin-bottom:16px;word-wrap:normal;padding:16px;overflow:auto;line-height:1.45;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px"><code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,'Liberation Mono',Menlo,Courier,monospace;padding:0px;margin:0px;background-color:transparent;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal;border:0px;display:inline;overflow:visible;line-height:inherit;word-wrap:normal">client_with_many_addresses = {
  details: {
    first_name: "Florentino",
    last_name: "Perez"
  },
  addresses: [
    {
      type: "home",
      postcode: "SE1 9SG",
      street: "London Bridge St",
      number: 32,
      city: "London",
      location: {
        latitude: 51.504382,
        longitude: -0.086279
      }
    },
    {
      type: "office",
      postcode: "SW1A 1AA",
      street: "Buckingham Palace Road",
      number: nil,
      city: "London",
      location: {
        latitude: 51.5013673,
        longitude: -0.1440787
      }
    }
  ]
}

client_with_many_addresses.dig_and_collect(:addresses, :location, :latitude)
#=> [51.504382, 51.5013673]</code></pre></pre>
</div>
<div>-- <br>
</div>
<div data-smartmail="gmail_signature">
<div>
<div>
<div>
<div>
<div style="font-size:12.8px">
<div><font face="times new roman, serif"><b>Alfredo Motta</b>, Ph.D. Software Engineering<br>
</font></div>
<font face="times new roman, serif">About me: <a href="https://www.alfredo.motta.name/" target="_blank">https://www.alfredo.motta.name</a></font></div>
<div style="font-size:12.8px"><font face="times new roman, serif">Linkedin: <a href="https://linkedin.com/in/alfredomotta" target="_blank">https://linkedin.com/in/alfredomotta</a></font></div>
</div>
<div><br>
</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></div>