Class: Pry::Command::WatchExpression::Expression
- Defined in:
- lib/pry/commands/watch_expression/expression.rb
Instance Attribute Summary collapse
-
#previous_value ⇒ Object
readonly
Returns the value of attribute previous_value.
-
#pry_instance ⇒ Object
readonly
Returns the value of attribute pry_instance.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#changed? ⇒ Boolean
Has the value of the expression changed?.
- #eval! ⇒ Object
-
#initialize(pry_instance, target, source) ⇒ Expression
constructor
A new instance of Expression.
- #to_s ⇒ Object
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_value ⇒ Object (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_instance ⇒ Object (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 |
#source ⇒ Object (readonly)
Returns the value of attribute source.
7 8 9 |
# File 'lib/pry/commands/watch_expression/expression.rb', line 7 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
7 8 9 |
# File 'lib/pry/commands/watch_expression/expression.rb', line 7 def target @target end |
#value ⇒ Object (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)
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_s ⇒ Object
20 21 22 |
# File 'lib/pry/commands/watch_expression/expression.rb', line 20 def to_s "#{Code.new(source).highlighted.strip} => #{value}" end |