Sha256: 38f020392bd457677ac081fd4336d9d6a80f1c11c708d565156b65c86e544db0

Contents?: true

Size: 1.06 KB

Versions: 6790

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

class Pry
  class Command
    class WatchExpression
      class Expression
        attr_reader :target, :source, :value, :previous_value, :pry_instance

        def initialize(pry_instance, target, source)
          @pry_instance = pry_instance
          @target = target
          @source = Code.new(source).strip
        end

        def eval!
          @previous_value = value
          @value = Pry::ColorPrinter.pp(target_eval(target, source), ''.dup)
        end

        def to_s
          "#{Code.new(source).highlighted.strip} => #{value}"
        end

        # Has the value of the expression changed?
        #
        # We use the pretty-printed string represenation to detect differences
        # as this avoids problems with dup (causes too many differences) and ==
        # (causes too few)
        def changed?
          (value != previous_value)
        end

        private

        def target_eval(target, source)
          target.eval(source)
        rescue StandardError => e
          e
        end
      end
    end
  end
end

Version data entries

6,790 entries across 6,786 versions & 31 rubygems

Version Path
cybrid_api_organization_ruby-0.123.143 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb
cybrid_api_id_ruby-0.123.143 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb
cybrid_api_bank_ruby-0.123.142 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb
cybrid_api_id_ruby-0.123.142 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb
cybrid_api_organization_ruby-0.123.142 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb
cybrid_api_bank_ruby-0.123.140 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb
cybrid_api_id_ruby-0.123.140 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb
cybrid_api_organization_ruby-0.123.140 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb
cybrid_api_bank_ruby-0.123.139 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb
cybrid_api_id_ruby-0.123.139 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb
cybrid_api_organization_ruby-0.123.139 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb
cybrid_api_id_ruby-0.123.137 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb
cybrid_api_organization_ruby-0.123.137 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb
cybrid_api_bank_ruby-0.123.137 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb
cybrid_api_organization_ruby-0.123.135 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb
cybrid_api_bank_ruby-0.123.135 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb
cybrid_api_id_ruby-0.123.135 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb
cybrid_api_bank_ruby-0.123.134 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb
cybrid_api_id_ruby-0.123.134 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb
cybrid_api_organization_ruby-0.123.134 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/commands/watch_expression/expression.rb