Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Regexp with some kinds of interpolation get transformed into comments. #82

Open
@envygeeks

Description

@envygeeks

Full example:

module EnvyGeeks
  module Get extend self
    def ips(cidr = "192.168.1.0/24")
      # Technically we don't need the select but we should defensively double chck.
      `ip route show #{cidr}`.each_line.select { |v| v =~ /scope link/ }.map do |v|
        IPAddr.new(v.match(/(?:src )(#{Regexp.escape(cidr.gsub(/\/\d+\Z/, "").gsub(/\.\d+\Z/, ""))}\.\d+)/)[1])
      end
    end
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions