Class: Pry::Command::WatchExpression::Expression
- Defined in:
- lib/pry/commands/watch_expression/expression.rb
Instance Attribute Summary collapse
-
#_pry_ ⇒ Object
readonly
Returns the value of attribute pry.
-
#previous_value ⇒ Object
readonly
Returns the value of attribute previous_value.
-
#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_, target, source) ⇒ Expression
constructor
A new instance of Expression.
- #to_s ⇒ Object
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_value ⇒ Object (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 |
#source ⇒ Object (readonly)
Returns the value of attribute source.
4 5 6 |
# File 'lib/pry/commands/watch_expression/expression.rb', line 4 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
4 5 6 |
# File 'lib/pry/commands/watch_expression/expression.rb', line 4 def target @target end |
#value ⇒ Object (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)
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_s ⇒ Object
17 18 19 |
# File 'lib/pry/commands/watch_expression/expression.rb', line 17 def to_s "#{Code.new(source).highlighted.strip} => #{value}" end |