Skip to content

Instantly share code, notes, and snippets.

@epitron
Created April 26, 2011 02:46
Show Gist options
  • Save epitron/941702 to your computer and use it in GitHub Desktop.
Save epitron/941702 to your computer and use it in GitHub Desktop.
#
# Creates a new CommandSet and automatically mixes it into Pry::Commands.
#
Pry.plugin :test do
settings do
bool :make_awesome, :default => true
enum :goat_type, :default => "plain", :options => %w[ plain mountain billy ]
string :favorite_goat, :default => "Super Dave the Goat", :validate => proc { goat[/super/i] }
int :expire_goats, :default => 5.minutes
end
helpers do
def helper
"I HELP GOATS"
end
end
command "help-a-goat" do
output.puts helper
end
# A stand-alone setting (to keep related things grouped together)
setting :max_goats, :default => proc { free_memory / goat_size }
command "add-goat" do |arg|
@goats ||= []
raise InvalidGoatError if @goats.size > settings.max_goats
@goats << Goat.new(arg)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment