Permalink
Browse files

Ruby 1.9.2: Use sample method instead of Facets' pick, always add cur…

…rent directory and/or autumn root directory to $:
  • Loading branch information...
1 parent 2cbde7c commit e2b9460a4bc36197b653b2386cde2cbec6d7807a @RISCfuture RISCfuture committed Aug 30, 2010
Showing with 16 additions and 13 deletions.
  1. +4 −6 README.rdoc
  2. +2 −0 Rakefile
  3. +3 −3 leaves/insulter/controller.rb
  4. +0 −2 libs/genesis.rb
  5. +2 −1 script/console
  6. +1 −0 script/daemon
  7. +1 −0 script/destroy
  8. +1 −0 script/generate
  9. +2 −1 script/server
View
10 README.rdoc
@@ -169,13 +169,11 @@ constant. Now, we'll want it to respond to the "!fortune" command, and all you
have to do is create a method called +fortune_command+ to make it work:
def fortune_command(stem, sender, reply_to, msg)
- FORTUNES.pick
+ FORTUNES.sample
end
-The +pick+ method is provided by Facets, so you may need to add a <tt>require
-'facets/random'</tt> line at the top of your file. Our method returns a fortune
-at random, which is automatically transmitted to the channel or nick where the
-command was received.
+Our method returns a fortune at random, which is automatically transmitted to
+the channel or nick where the command was received.
Of course, any self-respecting fortune bot announces its presence when it starts
up, so, in your +Controller+ class, override the Autumn::Leaf#did_start_up
@@ -248,7 +246,7 @@ ERb parser by using the Autumn::Leaf#var method. Let's upgrade our
+fortune_command+ method for that:
def fortune_command(stem, sender, reply_to, msg)
- var :fortune => FORTUNES.pick
+ var :fortune => FORTUNES.sample
end
We can then write a view, fortune.txt.erb, which will render the fortune:
View
2 Rakefile
@@ -1,5 +1,7 @@
require 'rake'
+$: << Dir.getwd
require 'libs/autumn'
+$: << Autumn::Config.root unless Autumn::Config.root == Dir.getwd
require 'libs/genesis'
task :default do
View
6 leaves/insulter/controller.rb
@@ -57,9 +57,9 @@ def about_command(stem, sender, reply_to, msg)
]
def insult(victim)
- var :adjective => ADJECTIVES.pick
- var :participle => PARTICIPLES.pick
- var :noun => NOUNS.pick
+ var :adjective => ADJECTIVES.sample
+ var :participle => PARTICIPLES.sample
+ var :noun => NOUNS.sample
var :victim => victim
end
end
View
2 libs/genesis.rb
@@ -81,8 +81,6 @@ def load_post_config_files
Bundler.require(:default, config.global(:season).to_sym)
- require 'facets/random'
-
require 'libs/misc'
require 'libs/authentication'
require 'libs/formatting'
View
3 script/console
@@ -2,6 +2,7 @@
#
# Launches an IRb console with the Autumn environment loaded.
+$: << Dir.getwd
require 'libs/autumn'
Dir.chdir Autumn::Config.root
@@ -23,4 +24,4 @@ libs << " -r libs/console_boot"
require 'libs/genesis'
puts "Loading Autumn #{Autumn::Config.version}..."
-exec "#{options[:irb]} #{libs}"
+exec "#{options[:irb]} -I. #{libs}"
View
1 script/daemon
@@ -24,6 +24,7 @@
require 'rubygems'
require 'daemons'
+$: << Dir.getwd
require 'libs/autumn'
Daemons.run "#{Autumn::Config.root}/script/server", :app_name => 'autumn', :dir_mode => :normal, :dir => "#{Autumn::Config.root}/tmp", :multiple => false, :backtrace => true, :monitor => false, :log_output => true
View
1 script/destroy
@@ -19,6 +19,7 @@
# --vcs, -c:: Remove any created files or directories from the project's version
# control system. (Autodetects CVS and Subversion.)
+$: << Dir.getwd
require 'libs/script'
opts = GetoptLong.new(
View
1 script/generate
@@ -19,6 +19,7 @@
# --vcs, -c:: Add any created files or directories to the project's version
# control system. (Autodetects CVS and Subversion.)
+$: << Dir.getwd
require 'libs/script'
opts = GetoptLong.new(
View
3 script/server
@@ -3,8 +3,9 @@
# Runs Autumn from the command line. This script will not exit until all leaves
# have exited. To use this script as a daemon, see the script/daemon script.
+$: << Dir.getwd
require 'libs/autumn'
-$: << Autumn::Config.root
+$: << Autumn::Config.root unless Autumn::Config.root == Dir.getwd
require 'libs/genesis'
puts "Loading Autumn #{Autumn::Config.version}"

0 comments on commit e2b9460

Please sign in to comment.