class Pry::Command::WatchExpression::Expression

Attributes

_pry_[R]
previous_value[R]
source[R]
target[R]
value[R]

Public Class Methods

new(_pry_, target, source) click to toggle source
# File lib/pry/commands/watch_expression/expression.rb, line 6
def initialize(_pry_, target, source)
  @_pry_ = _pry_
  @target = target
  @source = Code.new(source).strip
end

Public Instance Methods

changed?() click to toggle source

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)

# File lib/pry/commands/watch_expression/expression.rb, line 25
def changed?
  (value != previous_value)
end
eval!() click to toggle source
# File lib/pry/commands/watch_expression/expression.rb, line 12
def eval!
  @previous_value = @value
  @value = Pry::ColorPrinter.pp(target_eval(target, source), "")
end
to_s() click to toggle source
# File lib/pry/commands/watch_expression/expression.rb, line 17
def to_s
  "#{Code.new(source).highlighted.strip} => #{value}"
end