Sha256: 0ef5c31b44ec77a4d69b0f61f5def5559db7a96f90f6008879a1780a3691b36f

Contents?: true

Size: 1.33 KB

Versions: 6796

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

class Pry
  class Command
    class Ls < Pry::ClassCommand
      class LocalVars < Pry::Command::Ls::Formatter
        def initialize(opts, pry_instance)
          super(pry_instance)
          @default_switch = opts[:locals]
          @sticky_locals = pry_instance.sticky_locals
        end

        def output_self
          locals = @target.eval('local_variables').reject do |e|
            @sticky_locals.key?(e.to_sym)
          end
          name_value_pairs = locals.map do |name|
            [name, @target.eval(name.to_s)]
          end
          format(name_value_pairs).join('')
        end

        private

        def format(name_value_pairs)
          sorted = name_value_pairs.sort_by do |_name, value|
            value.to_s.size
          end
          sorted.reverse.map do |name, value|
            colorized_assignment_style(name, format_value(value))
          end
        end

        def colorized_assignment_style(lhs, rhs, desired_width = 7)
          colorized_lhs = color(:local_var, lhs)
          color_escape_padding = colorized_lhs.size - lhs.size
          pad = desired_width + color_escape_padding
          Kernel.format(
            "%-#{pad}<name>s = %<value>s",
            name: color(:local_var, colorized_lhs),
            value: rhs
          )
        end
      end
    end
  end
end

Version data entries

6,796 entries across 6,792 versions & 31 rubygems

Version Path
cybrid_api_bank_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ls/local_vars.rb
cybrid_api_id_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ls/local_vars.rb
cybrid_api_organization_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ls/local_vars.rb
cybrid_api_bank_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ls/local_vars.rb
cybrid_api_id_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ls/local_vars.rb
cybrid_api_organization_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ls/local_vars.rb
cybrid_api_bank_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ls/local_vars.rb
cybrid_api_id_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ls/local_vars.rb
cybrid_api_organization_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ls/local_vars.rb
cybrid_api_bank_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ls/local_vars.rb
cybrid_api_id_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ls/local_vars.rb
cybrid_api_organization_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ls/local_vars.rb
cybrid_api_bank_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ls/local_vars.rb
cybrid_api_id_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ls/local_vars.rb
cybrid_api_organization_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ls/local_vars.rb
avalara_sdk-24.12.1 vendor/bundle/ruby/2.7.0/gems/pry-0.13.1/lib/pry/commands/ls/local_vars.rb
cybrid_api_bank_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ls/local_vars.rb
cybrid_api_organization_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ls/local_vars.rb
cybrid_api_id_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ls/local_vars.rb
cybrid_api_bank_ruby-0.123.124 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/ls/local_vars.rb