Remove item from enum ruby

Viewed 39

I have this code here that gets a region and add to my variable "regions". So let' say it has: XYZ, DDA, BBB, .... Let's say I want to get everything but DDA. How can I do that.

Code:

def supported_regions(partition)
  if @@supported_regions_by_partition_cache[partition].nil?
    regions = xrp_supported_regions({ignore_build_status: IGNORE_BUILD_STATUS})
      .map { |region| rip_helper.get_region(region) }
      .select { |region| region.arn_partition == partition }
      .sort_by(&:region_name)
      .map(&:airport_code)
    @@supported_regions_by_partition_cache[partition] = regions
  else
    regions = @@supported_regions_by_partition_cache[partition]
  end
  regions
end

I already tried doing:

regions.delete('DDA')

also

.reject {|s| 'DDA' != s }

Not sure how I can do this. I am very new on Ruby.

1 Answers

You can use the select method and replace this line:

FROM

      .select { |region| region.arn_partition == partition }

TO

      .select { |region| region.arn_partition == partition && region.region_name != "DDA" }
Related