Class: Pry

Inherits:
Object
  • Object
show all
Defined in:
lib/pry/hack.rb

Defined Under Namespace

Modules: Hackage

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_hack(type, handle, hack) ⇒ Pry::Hackage::Hack

Adds a hack to pry for use in the REPL.

Parameters:

  • type (Symbol)

    The type of hack which is being added, this decides the placement of the object in Pry.config.hack.s

  • handle (Object)

    A name to give to the hack, this is needed to remove the hack from the environment as well.

  • hack (Pry::Hackage::Hack)

    The hack that will be added to Pry. See Pry::Hackage::Hack

Returns:



42
43
44
45
# File 'lib/pry/hack.rb', line 42

def self.add_hack(type, handle, hack)
  (eval "self.config.hack.s.#{self.config.hack.implications.send(:method_missing, type)||type}")[handle] = hack
  return hack
end

.remove_hack(type, handle) ⇒ Fixnum

Removes a method from use in the REPL, added by add_hack

Parameters:

  • type (Object)

    The name that was assigned to the hack at the time it was added.

Returns:

  • (Fixnum)

    handle The number of hacks with the name given that were removed from the environment.



53
54
55
56
57
# File 'lib/pry/hack.rb', line 53

def self.remove_hack(type, handle)
  si = self.config.hack.collect(&:size).reduce(0,:+)
  self.config.hack.each {|hash| hash.delete(handle)}
  return si - self.config.hack.collect(&:size).reduce(0,:+)
end

Instance Method Details

#old_retrieve_lineObject



218
# File 'lib/pry/hack.rb', line 218

alias_method :old_retrieve_line, :retrieve_line

#retrieve_line(eval_string, *args) ⇒ Object



220
221
222
223
# File 'lib/pry/hack.rb', line 220

def retrieve_line(eval_string, *args)
  old_retrieve_line(eval_string, *args)
  puts eval_string.sub!(/^.+?$/, Hackage.hack_line(eval_string))
end