mercredi 29 novembre 2017

Ruby class method data filter

I have data inside of a ruby class method that i want to filter. The class method Clothes.data contains the following array

Clothes.data class method

[
  {
    "Type"=>"Sweater",
    "Size"=>"Large",
    "Material"=>"Wool"
  },
  {
    "Type"=>"Hoodie",
    "Size"=>"Medium",
    "Material"=>"Cotton"
  },
  {
    "Type"=>"Jeans",
    "Size"=>"Small",
    "Material"=>"Denim"
  }         
]

I want to filter the string "Wool" from the class method Clothes.data . And then return the string reversed. Here's what I have tried.

def nice_material
  Clothes.data.map @Material.reverse
end

This currently returns the array => ["Wool", "Wool", "Wool"] . The instance method @Material represents the first Material.

Instead, I want the method to only return the reverse of the string "Wool" ("looW")

Aucun commentaire:

Enregistrer un commentaire