<commit_before>require "active_support/hash_with_indifferent_access"
require "active_support/core_ext/hash/indifferent_access"
require "active_support/core_ext/module/delegation"
require "scash/version"

class Scash
  include Enumerable
  delegate  :each, :empty?, :eql?, :has_key?, :has_value?, :include?, :index,
            :keys, :merge, :reject, :replace, :select, :size, :values, :to => :to_hash

  attr_reader :stack

  def initialize(variables = {}, klass = HashWithIndifferentAccess)
    @klass = klass
    @hash = convert(variables)
    @inverse_hash = convert(variables)
  end

  def to_hash
    @hash
  end

  def to_inverse_hash
    @inverse_hash
  end

  def scope(variables)
    previous_hash = @hash.select{|key|variables.key?(key.to_s) || variables.key?(key.to_sym)}
    previous_inverse_hash = @inverse_hash.select{|key|variables.key?(key.to_s) || variables.key?(key.to_sym)}
    @hash.merge! variables
    @inverse_hash.merge!(variables.reject{|key| @inverse_hash.key?(key)})
    yield
  ensure
    variables.keys.each{|key| @hash.delete(key)}
    variables.keys.each{|key| @inverse_hash.delete(key)}
    @inverse_hash.merge!(previous_inverse_hash)
    @hash.merge!(previous_hash)
    @hash.merge!(global_variables.reject { |k| @hash.has_key?(k) })
  end
  alias :with :scope

  def [](key, inverse = false)
    if inverse
      @inverse_hash[key]<commit_msg>Rewrite keys.each into each_key<commit_after>require "active_support/hash_with_indifferent_access"
require "active_support/core_ext/hash/indifferent_access"
require "active_support/core_ext/module/delegation"
require "scash/version"

class Scash
  include Enumerable
  delegate  :each, :empty?, :eql?, :has_key?, :has_value?, :include?, :index,
            :keys, :merge, :reject, :replace, :select, :size, :values, :to => :to_hash

  attr_reader :stack

  def initialize(variables = {}, klass = HashWithIndifferentAccess)
    @klass = klass
    @hash = convert(variables)
    @inverse_hash = convert(variables)
  end

  def to_hash
    @hash
  end

  def to_inverse_hash
    @inverse_hash
  end

  def scope(variables)
    previous_hash = @hash.select{|key|variables.key?(key.to_s) || variables.key?(key.to_sym)}
    previous_inverse_hash = @inverse_hash.select{|key|variables.key?(key.to_s) || variables.key?(key.to_sym)}
    @hash.merge! variables
    @inverse_hash.merge!(variables.reject{|key| @inverse_hash.key?(key)})
    yield
  ensure
    variables.each_key{|key| @hash.delete(key)}
    variables.each_key{|key| @inverse_hash.delete(key)}
    @inverse_hash.merge!(previous_inverse_hash)
    @hash.merge!(previous_hash)
    @hash.merge!(global_variables.reject { |k| @hash.has_key?(k) })
  end
  alias :with :scope

  def [](key, inverse = false)
    if inverse
      @inverse_hash[key]
{'fraction_non_alphanumeric': 0.13672438672438672, 'fraction_numerical': 0.0, 'mean_word_length': 4.557114228456914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '288325', 'n_tokens_mistral': 969, 'n_tokens_neox': 938, 'n_words': 170}