Skip to content
Newer
Older
100644 37 lines (29 sloc) 1.37 KB
1a9738f @banister refactored example initialization code (still need to update examples…
banister authored Jun 3, 2011
1 require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
548b4f8 @banister added import_from, delete, run to command API. Also added examples, a…
banister authored Jan 21, 2011
2
3 class MathCommands < Pry::CommandBase
4 command "greet", "Greet a person, e.g: greet john" do |name|
5 output.puts "Good afternoon #{name.capitalize}! Do you like Math?"
6 end
7
8 command "add", "Add a list of numbers together, e.g: add 1 2 3 4" do |*args|
9 output.puts "Total: #{args.map(&:to_f).inject(&:+)}"
10 end
11
12 command "multiply", "Multiply a list of numbers together, e.g: multiply 1 2 3 4" do |*args|
13 output.puts "Total: #{args.map(&:to_f).inject(&:*)}"
14 end
15
16 # Explicitly giving a description of "" to prevent command being
17 # displayed in 'help'
18 command "exit", "" do
19 throw :breakout, 0
20 end
18553b4 @banister Updated more docs and formatting.
banister authored Jan 21, 2011
21
22 # Bring in the "!" method from Pry::Commands
23 import_from Pry::Commands, "!"
548b4f8 @banister added import_from, delete, run to command API. Also added examples, a…
banister authored Jan 20, 2011
24 end
25
26 # Since we provide math commands, let's have mathematical
27 # before_session and after_session hooks, and a mathematical prompt
18553b4 @banister Updated more docs and formatting.
banister authored Jan 21, 2011
28 math_prompt = [proc { "math> " }, proc { "math* " }]
548b4f8 @banister added import_from, delete, run to command API. Also added examples, a…
banister authored Jan 20, 2011
29 math_hooks = {
30 :before_session => proc { |output, *| output.puts "Welcome! Let's do some math! Type 'help' for a list of commands." },
31 :after_session => proc { |output, *| output.puts "Goodbye!" }
32 }
33
34 # Start a Pry session using the commands defined in MyCommands
35 # Type 'help' in Pry to get a list of the commands and their descriptions
36 Pry.start(TOPLEVEL_BINDING, :commands => MathCommands, :prompt => math_prompt, :hooks => math_hooks)
Something went wrong with that request. Please try again.