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_, target, source) ⇒ Expression

Returns a new instance of Expression.



6
7
8
9
10
# 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

Instance Attribute Details

#_pry_Object (readonly)

Returns the value of attribute pry.



4
5
6
# File 'lib/pry/commands/watch_expression/expression.rb', line 4

def _pry_
  @_pry_
end

#previous_valueObject (readonly)

Returns the value of attribute previous_value.



4
5
6
# File 'lib/pry/commands/watch_expression/expression.rb', line 4

def previous_value
  @previous_value
end

#sourceObject (readonly)

Returns the value of attribute source.



4
5
6
# File 'lib/pry/commands/watch_expression/expression.rb', line 4

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



4
5
6
# File 'lib/pry/commands/watch_expression/expression.rb', line 4

def target
  @target
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/pry/commands/watch_expression/expression.rb', line 4

def value
  @value
end

Instance Method Details

#changed?Boolean

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)

Returns:

  • (Boolean)


25
26
27
# File 'lib/pry/commands/watch_expression/expression.rb', line 25

def changed?
  (value != previous_value)
end

#eval!Object



12
13
14
15
# 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_sObject



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

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