Skip to content

Formatters cannot be set/got when your implementation does not support Ractors #191

Open
@enebo

Description

@enebo

I was not passing some MRI pattern matching specs and realized that it was not setting the NullFormatter. It is because formatter requires Ractors to work.

I did a quick fix:

  # Returns the currently set formatter. By default, it is set to +DidYouMean::Formatter+.
  def self.formatter
    storage = defined?(Ractor) ? Ractor : Thread
    storage.current[:__did_you_mean_formatter__] || Formatter
  end

  # Updates the primary formatter used to format the suggestions.
  def self.formatter=(formatter)
    storage = defined?(Ractor) ? Ractor : Thread
    storage.current[:__did_you_mean_formatter__] = formatter
  end

but I suspect this is not right. This is a global setting and not just a thread-specific one...or is it?

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