<commit_before>
require 'ripl'

module Ripl::Rc; end
module Ripl::Rc::Anchor
  def loop_eval(str)
    case obj_or_binding = (config[:rc_anchor] ||= []).last
      when NilClass
        super

      when Binding
        @binding = obj_or_binding
        super

      else
        obj_or_binding.instance_eval(str, "(#{@name})", @line)
    end
  end

  def prompt
    if Ripl::Rc.const_defined?(:Color) && kind_of?(Ripl::Rc::Color) &&
       obj_or_binding = (config[:rc_anchor] ||= []).last

      super.sub(@name, format_result(obj_or_binding, @name))
    else
      super
    end
  end

  # if the object is the same, then we're exiting from an anchor,
  # so don't print anything.
  def print_result result
    super unless result != nil &&
                 result.object_id == Ripl.config[:rc_anchor_last].object_id
  end

  module Imp
    def short_inspect obj_or_binding
      obj_or_binding.inspect[0..9]
    end
  end

  module AnchorImp
    def anchor obj_or_binding
      if Ripl.config[:rc_init].nil?
        Ripl::Runner.load_rc(Ripl.config[:riplrc])
        Ripl.config[:rc_init] = true
      end

      (Ripl.config[:rc_anchor] ||= []) << obj_or_binding
      name = Ripl::Rc::U.short_inspect(obj_or_binding)
      Ripl::Shell.create(Ripl.config.merge(
        :name   => name,
        :prompt => "#{name}(#{Ripl.config[:rc_anchor].size})" +
                   Ripl.config[:prompt])).loop

      # stores to check if we're exiting from an anchor
      Ripl.config[:rc_anchor_last] = Ripl.config[:rc_anchor].pop
    end
  end
end

module Ripl::Rc::U; extend Ripl::Rc::Anchor::Imp; end

Ripl::Shell.include(Ripl::Rc::Anchor)

Ripl.extend(Ripl::Rc::Anchor::AnchorImp)
Ripl.config[:prompt] ||= Ripl::Shell::OPTIONS[:prompt]<commit_msg>anchor.rb: rearrange order<commit_after>
require 'ripl'

module Ripl::Rc; end
module Ripl::Rc::Anchor
  def loop_eval(str)
    case obj_or_binding = (config[:rc_anchor] ||= []).last
      when NilClass
        super

      when Binding
        @binding = obj_or_binding
        super

      else
        obj_or_binding.instance_eval(str, "(#{@name})", @line)
    end
  end

  def prompt
    if Ripl::Rc.const_defined?(:Color) && kind_of?(Ripl::Rc::Color) &&
       obj_or_binding = (config[:rc_anchor] ||= []).last

      super.sub(@name, format_result(obj_or_binding, @name))
    else
      super
    end
  end

  # if the object is the same, then we're exiting from an anchor,
  # so don't print anything.
  def print_result result
    super unless result != nil &&
                 result.object_id == Ripl.config[:rc_anchor_last].object_id
  end

  module Imp
    def short_inspect obj_or_binding
      obj_or_binding.inspect[0..9]
    end
  end

  module AnchorImp
    def anchor obj_or_binding
      if Ripl.config[:rc_init].nil?
        Ripl::Runner.load_rc(Ripl.config[:riplrc])
        Ripl.config[:rc_init] = true
      end

      (Ripl.config[:rc_anchor] ||= []) << obj_or_binding
      name = Ripl::Rc::U.short_inspect(obj_or_binding)
      Ripl::Shell.create(Ripl.config.merge(
        :name   => name,
        :prompt => "#{name}(#{Ripl.config[:rc_anchor].size})" +
                   Ripl.config[:prompt])).loop

      # stores to check if we're exiting from an anchor
      Ripl.config[:rc_anchor_last] = Ripl.config[:rc_anchor].pop
    end
  end
end

module Ripl::Rc::U; extend Ripl::Rc::Anchor::Imp; end

Ripl::Shell.include(Ripl::Rc::Anchor)
Ripl.config[:prompt] ||= Ripl::Shell::OPTIONS[:prompt]

Ripl.extend(Ripl::Rc::Anchor::AnchorImp) # define Ripl.anchor
{'fraction_non_alphanumeric': 0.1368540601930721, 'fraction_numerical': 0.001135718341851221, 'mean_word_length': 2.976297968397291, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2186503', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1221, 'n_words': 245}