mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
refactored example initialization code (still need to update examples for new API)
This commit is contained in:
parent
61bb4d9a17
commit
1a9738ff11
11 changed files with 24 additions and 48 deletions
|
@ -1,7 +1,4 @@
|
||||||
direc = File.dirname(__FILE__)
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||||
|
|
||||||
require 'rubygems'
|
|
||||||
require "#{direc}/../lib/pry"
|
|
||||||
|
|
||||||
# define a local.
|
# define a local.
|
||||||
a = "a local variable"
|
a = "a local variable"
|
||||||
|
@ -14,4 +11,5 @@ end
|
||||||
# Start pry session at top-level.
|
# Start pry session at top-level.
|
||||||
# The local variable `a` and the `hello` method will
|
# The local variable `a` and the `hello` method will
|
||||||
# be accessible.
|
# be accessible.
|
||||||
|
puts __LINE__
|
||||||
binding.pry
|
binding.pry
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
direc = File.dirname(__FILE__)
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||||
|
|
||||||
require 'rubygems'
|
|
||||||
require "#{direc}/../lib/pry"
|
|
||||||
|
|
||||||
# Inherit standard command set, but tweak them by importing some and
|
# Inherit standard command set, but tweak them by importing some and
|
||||||
# overriding others.
|
# overriding others.
|
||||||
|
@ -18,7 +15,7 @@ class MyCommands < Pry::CommandBase
|
||||||
|
|
||||||
# analogy to Ruby's native alias_method idiom for decorating a method
|
# analogy to Ruby's native alias_method idiom for decorating a method
|
||||||
alias_command "old_status", "status", ""
|
alias_command "old_status", "status", ""
|
||||||
|
|
||||||
# Invoke one command from within another using `run`
|
# Invoke one command from within another using `run`
|
||||||
command "status", "Modified status." do |x|
|
command "status", "Modified status." do |x|
|
||||||
output.puts "About to show status, are you ready?"
|
output.puts "About to show status, are you ready?"
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
direc = File.dirname(__FILE__)
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||||
|
|
||||||
require 'rubygems'
|
|
||||||
require "#{direc}/../lib/pry"
|
|
||||||
|
|
||||||
class MathCommands < Pry::CommandBase
|
class MathCommands < Pry::CommandBase
|
||||||
command "greet", "Greet a person, e.g: greet john" do |name|
|
command "greet", "Greet a person, e.g: greet john" do |name|
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
direc = File.dirname(__FILE__)
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||||
|
|
||||||
require 'rubygems'
|
|
||||||
require "#{direc}/../lib/pry"
|
|
||||||
|
|
||||||
my_hooks = {
|
my_hooks = {
|
||||||
:before_session => proc { |out, target| out.puts "Opening #{target.eval('self')}." },
|
:before_session => proc { |out, target| out.puts "Opening #{target.eval('self')}." },
|
||||||
:after_session => proc { |out, target| out.puts "Closing #{target.eval('self')}." }
|
:after_session => proc { |out, target| out.puts "Closing #{target.eval('self')}." }
|
||||||
}
|
}
|
||||||
|
|
||||||
# Start a Pry session using the hooks hash defined in my_hooks
|
# Start a Pry session using the hooks hash defined in my_hooks
|
||||||
Pry.start(TOPLEVEL_BINDING, :hooks => my_hooks)
|
Pry.start(TOPLEVEL_BINDING, :hooks => my_hooks)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Note: this requires you to have Gosu and TexPlay installed.
|
# Note: this requires you to have Gosu and TexPlay installed.
|
||||||
# `gem install gosu`
|
# `gem install gosu`
|
||||||
# `gem install texplay`
|
# `gem install texplay`
|
||||||
#
|
#
|
||||||
# Extra instructions for installing Gosu on Linux can be found here:
|
# Extra instructions for installing Gosu on Linux can be found here:
|
||||||
# http://code.google.com/p/gosu/wiki/GettingStartedOnLinux
|
# http://code.google.com/p/gosu/wiki/GettingStartedOnLinux
|
||||||
#
|
#
|
||||||
|
@ -10,11 +10,7 @@
|
||||||
#
|
#
|
||||||
# Have fun! :)
|
# Have fun! :)
|
||||||
|
|
||||||
direc = File.dirname(__FILE__)
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||||
|
|
||||||
require 'rubygems'
|
|
||||||
require "texplay"
|
|
||||||
require "#{direc}/../lib/pry"
|
|
||||||
|
|
||||||
WIDTH = 640
|
WIDTH = 640
|
||||||
HEIGHT = 480
|
HEIGHT = 480
|
||||||
|
@ -42,12 +38,12 @@ class WinClass < Gosu::Window
|
||||||
@img.rect 0, 0, @img.width - 1, @img.height - 1
|
@img.rect 0, 0, @img.width - 1, @img.height - 1
|
||||||
|
|
||||||
@binding = Pry.binding_for(@img)
|
@binding = Pry.binding_for(@img)
|
||||||
|
|
||||||
@pry_instance = Pry.new(:commands => ImageCommands, :prompt => IMAGE_PROMPT)
|
@pry_instance = Pry.new(:commands => ImageCommands, :prompt => IMAGE_PROMPT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
@img.draw_rot(WIDTH / 2, HEIGHT / 2, 1, 0, 0.5, 0.5)
|
@img.draw_rot(WIDTH / 2, HEIGHT / 2, 1, 0, 0.5, 0.5)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
direc = File.dirname(__FILE__)
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||||
|
|
||||||
require 'rubygems'
|
|
||||||
require "#{direc}/../lib/pry"
|
|
||||||
|
|
||||||
# Create a StringIO that contains the input data
|
# Create a StringIO that contains the input data
|
||||||
str_input = StringIO.new("puts 'hello world!'\nputs \"I am in \#{self}\"\nexit")
|
str_input = StringIO.new("puts 'hello world!'\nputs \"I am in \#{self}\"\nexit")
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
direc = File.dirname(__FILE__)
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||||
|
|
||||||
require 'rubygems'
|
|
||||||
require "#{direc}/../lib/pry"
|
|
||||||
|
|
||||||
# Create a StringIO that contains the input data for all the Pry objects
|
# Create a StringIO that contains the input data for all the Pry objects
|
||||||
cmds = <<-CMDS
|
cmds = <<-CMDS
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
direc = File.dirname(__FILE__)
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||||
|
|
||||||
require 'rubygems'
|
|
||||||
require "#{direc}/../lib/pry"
|
|
||||||
|
|
||||||
# Create a StringIO to contain the output data
|
# Create a StringIO to contain the output data
|
||||||
str_output = StringIO.new
|
str_output = StringIO.new
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
direc = File.dirname(__FILE__)
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||||
|
|
||||||
require 'rubygems'
|
|
||||||
require "#{direc}/../lib/pry"
|
|
||||||
|
|
||||||
my_print = proc { |out, value| out.puts "Output is: #{value.inspect}" }
|
my_print = proc { |out, value| out.puts "Output is: #{value.inspect}" }
|
||||||
|
|
||||||
# Start a Pry session using the print object defined in my_print
|
# Start a Pry session using the print object defined in my_print
|
||||||
Pry.start(TOPLEVEL_BINDING, :print => my_print)
|
Pry.start(TOPLEVEL_BINDING, :print => my_print)
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
direc = File.dirname(__FILE__)
|
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||||
|
|
||||||
require 'rubygems'
|
|
||||||
require "#{direc}/../lib/pry"
|
|
||||||
|
|
||||||
# Remember, first prompt in array is the main prompt, second is the wait
|
# Remember, first prompt in array is the main prompt, second is the wait
|
||||||
# prompt (used for multiline input when more input is required)
|
# prompt (used for multiline input when more input is required)
|
||||||
my_prompt = [ proc { |obj, *| "inside #{obj}> " },
|
my_prompt = [ proc { |obj, *| "inside #{obj}> " },
|
||||||
proc { |obj, *| "inside #{obj}* "} ]
|
proc { |obj, *| "inside #{obj}* "} ]
|
||||||
|
|
||||||
# Start a Pry session using the prompt defined in my_prompt
|
# Start a Pry session using the prompt defined in my_prompt
|
||||||
Pry.start(TOPLEVEL_BINDING, :prompt => my_prompt)
|
Pry.start(TOPLEVEL_BINDING, :prompt => my_prompt)
|
||||||
|
|
6
examples/helper.rb
Normal file
6
examples/helper.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
require 'rubygems'
|
||||||
|
unless Object.const_defined? 'Pry'
|
||||||
|
$:.unshift File.expand_path '../../lib', __FILE__
|
||||||
|
require 'pry'
|
||||||
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue