Class: Pry::Command::WatchExpression::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/pry/commands/watch_expression/expression.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pry_instance, target, source) ⇒ Expression

Returns a new instance of Expression.



9
10
11
12
13
# File 'lib/pry/commands/watch_expression/expression.rb', line 9

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

Instance Attribute Details

#previous_valueObject (readonly)

Returns the value of attribute previous_value.



7
8
9
# File 'lib/pry/commands/watch_expression/expression.rb', line 7

def previous_value
  @previous_value
end

#pry_instanceObject (readonly)

Returns the value of attribute pry_instance.



7
8
9
# File 'lib/pry/commands/watch_expression/expression.rb', line 7

def pry_instance
  @pry_instance
end

#sourceObject (readonly)

Returns the value of attribute source.



7
8
9
# File 'lib/pry/commands/watch_expression/expression.rb', line 7

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



7
8
9
# File 'lib/pry/commands/watch_expression/expression.rb', line 7

def target
  @target
end

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/pry/commands/watch_expression/expression.rb', line 7

def value
  @value
end

Instance Method Details

#changed?Boolean

Has the value of the expression changed?

We use the pretty-printed string representation to detect differences as this avoids problems with dup (causes too many differences) and == (causes too few)

Returns:

  • (Boolean)


29
30
31
# File 'lib/pry/commands/watch_expression/expression.rb', line 29

def changed?
  (value != previous_value)
end

#eval!Object



15
16
17
18
# File 'lib/pry/commands/watch_expression/expression.rb', line 15

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

#to_sObject



20
21
22
# File 'lib/pry/commands/watch_expression/expression.rb', line 20

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