[LRUG] Feedback on Hash#dig_and_collect

Alfredo Motta motta.lrd at hotmail.it
Sat Oct 21 00:38:31 PDT 2017


Hello Rubyist, I am new here and looking forward to talk Ruby!

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)

Do you have any feedback on it?
https://github.com/mottalrd/hash_dig_and_collect

I wrote about the rationale here
http://www.alfredo.motta.name/making-ruby-hashdig-even-more-awesome-introducing-hashdig_and_collect/

Here is an example where I want the latitude of all the addresses of a given client.
Thank you for your help,
Happy weekend


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]

--
Alfredo Motta, Ph.D. Software Engineering
About me: https://www.alfredo.motta.name<https://www.alfredo.motta.name/>
Linkedin: https://linkedin.com/in/alfredomotta

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20171021/ca76a5a6/attachment.html>


More information about the Chat mailing list