Skip to content

Instantly share code, notes, and snippets.

View banister's full-sized avatar
🇳🇱

John Mair banister

🇳🇱
View GitHub Profile
pry(main)> show-method for_
From: (pry) @ line 0:
Number of lines: 6
def for_(var, cond, inc)
while(cond.call)
yield var
inc.call
end
require 'pry'
module PryDebug
class FileBreakpoint < Struct.new(:id, :file, :line)
def to_s
"breakpoint #{id} at #{file}:#{line}"
end
def is_at?(other_file, other_line)
other_file.end_with?(file) && other_line == line
@banister
banister / restartable.rb
Created June 3, 2011 02:25
manveru's nifty restartable exceptions
require 'continuation'
class RestartableError < StandardError
attr_accessor :cc
def self.call(msg)
instance = new(msg)
returning = true
callcc{|c| instance.cc = c }
returning = !returning
# -*- coding: utf-8 -*-
# Colors
require 'ap'
require 'term/ansicolor'
# Change some stupid monkey patches
class String
%w[gray red green yellow blue
pry(main)> import Pry::ExtendedCommands::Experimental
pry(main)> def validate_code
pry(main)* puts "hello, about to validate some code!"
pry(main)* show-input
0: def validate_code
1: puts "hello, about to validate some code!"
pry(main)* # oops forgot to add a parameter!
pry(main)* rue-0 def validate_code(code)
pry(main)* show-input
0: def validate_code(code)
irb quirk in 1.9.2:
o = Object.new
def o.blah
eval("T = 10")
end
o
T #=> 10 (in IRB)
* Pry::Helpers::Color:
** bold
** colorize
** blue
** bright_black
** brigt_cyan
** bright_green
** brigt_magenta
** bright_purple
** bright_red
module Helpers
def use_a_helper
puts "test"
end
end
class Pry::CommandContext
include Helpers
end
@MyArtChannel
MyArtChannel / development.rb
Created April 25, 2011 20:42
Use Pry as IRB replacement in rails 3 console
# Add this to the end of your development.rb and add
#
# gem 'pry'
#
# to your Gemfile and run bundle to install.
silence_warnings do
begin
require 'pry'
IRB = Pry
pry(main)> class SupBurg
pry(main)* def yo
pry(main)* puts 'swede'
pry(main)* end
pry(main)* end
=> nil
pry(main)> hist
0: class SupBurg
1: def yo
2: puts 'swede'