class PryMoves::Watch

Attributes

list[R]

Public Class Methods

new() click to toggle source
# File lib/pry-moves/watch.rb, line 9
def initialize
  @list = Set.new
end

Public Instance Methods

add(cmd, binding_) click to toggle source
# File lib/pry-moves/watch.rb, line 28
def add(cmd, binding_)
  @list << cmd
  puts eval_cmd(cmd, binding_)
end
empty?() click to toggle source
# File lib/pry-moves/watch.rb, line 53
def empty?
  @list.empty?
end
eval_cmd(cmd, binding_) click to toggle source
# File lib/pry-moves/watch.rb, line 43
def eval_cmd(cmd, binding_)
  "\033[1m#{cmd}\033[0m: #{format binding_.eval(cmd)}"
rescue NameError
  "\033[1m#{cmd}\033[0m: <undefined>"
end
format(text) click to toggle source
# File lib/pry-moves/watch.rb, line 49
def format(text)
  Pry::ColorPrinter.pp(text, "").strip
end
output(binding_) click to toggle source
# File lib/pry-moves/watch.rb, line 37
def output(binding_)
  @list.map do |cmd|
    eval_cmd(cmd, binding_)
  end.join "; "
end
print(binding_) click to toggle source
process_cmd(cmd, binding_) click to toggle source
# File lib/pry-moves/watch.rb, line 13
def process_cmd(cmd, binding_)
  case cmd
    when nil, ''
      if @list.count > 0
        print binding_
      else
        puts "Watch list is empty"
      end
    when '-clear', '-c'
      @list.clear
    else
      add cmd, binding_
  end
end