Skip to content

Idea: Preserve matchdata in rules #141

Description

@avdi

Here's part of a rule I just wrote the other day:

stampfile_pattern = %r"^members/(?<email>.*)/\d{2}-(?<step>\w+).timestamp$"
rule stampfile_pattern do |t|
  match           = stampfile_pattern.match(t.name)
  email           = match[:email]
  step            = match[:step]
  # ...
end

Notice how, after it matches, I have to re-apply the regex inside the rule definition in order to pull out named matchdata.

I was thinking of introducing something like this as an alternative:

stampfile_pattern = %r"^members/(?<email>.*)/\d{2}-(?<step>\w+).timestamp$"
rule stampfile_pattern do |t|
  email           = t.matchdata[:email]
  step            = t.matchdata[:step]
  # ...
end

Before I dive in, what do you think? And is there another way to accomplish this that I've missed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions