]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
Ruby 1.9 cleanup: variables warnings
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 12 Jan 2011 21:15:12 +0000 (22:15 +0100)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 12 Jan 2011 21:15:12 +0000 (22:15 +0100)
Fix most ruby 1.9 warnings about shadowed variables (still one remaining in
keywords.rb). The only significant changes are in the quiz game plugin.

Also fix an issue in dictclient where the block parameter of a method
was not correctly isolated from the previous parameter.

16 files changed:
data/rbot/plugins/dictclient.rb
data/rbot/plugins/factoids.rb
data/rbot/plugins/games/quiz.rb
data/rbot/plugins/games/uno.rb
data/rbot/plugins/geoip.rb
data/rbot/plugins/imdb.rb
data/rbot/plugins/iplookup.rb
data/rbot/plugins/lastfm.rb
data/rbot/plugins/rss.rb
data/rbot/plugins/slashdot.rb
data/rbot/plugins/urban.rb
lib/rbot/botuser.rb
lib/rbot/core/auth.rb
lib/rbot/core/utils/filters.rb
lib/rbot/core/utils/httputil.rb
lib/rbot/core/utils/wordlist.rb

index 34276dad0c901d518f75b794b2abf4e3a6a037cc..f55defa42cdd3ee261769696c7633394409d9062 100644 (file)
@@ -91,7 +91,7 @@ class DictClientPlugin < Plugin
   # the DICT object is automatically disconnected. the return value of the block
   # is returned from this method.
   # if an IRC message argument is passed, the error message will be replied
-  def with_dict(m=nil &block)
+  def with_dict(m=nil, &block)
     server, port = @bot.config['dictclient.server'].split ':' if @bot.config['dictclient.server']
     server ||= 'dict.org'
     port ||= DICT::DEFAULT_PORT
@@ -159,7 +159,7 @@ class DictClientPlugin < Plugin
       if results
         results.collect {|database, matches|
           @bot.config['dictclient.match_format'].gsub(
-            '<matches>', matches.collect {|m| format_headword m}.join(', ')
+            '<matches>', matches.collect {|hit| format_headword hit}.join(', ')
           ).gsub(
             '<database>', format_database(database)
           )
index 3ca190176b7705f922a6df638e2178344670ad17..452efb98fef3fb8b7ff3eb2a3a69fc27f56d3383 100644 (file)
@@ -65,7 +65,7 @@ class FactoidsPlugin < Plugin
     def index(f)
       fact = f.to_s
       return if fact.empty?
-      self.map { |f| f[:fact] }.index(fact)
+      self.map { |fs| fs[:fact] }.index(fact)
     end
 
     def delete(f)
index 63a5dde427e4ecd7429c7ba58e92ad2f84dafc34..d2e4ab97970bec1e8bfefe6a9dedf849c1246d24 100644 (file)
@@ -285,8 +285,10 @@ class QuizPlugin < Plugin
       jokers = q.registry[nick].jokers
 
       rank = 0
-      q.rank_table.each_index { |rank| break if nick.downcase == q.rank_table[rank][0].downcase }
-      rank += 1
+      q.rank_table.each do |place|
+        rank += 1
+        break if nick.downcase == place[0].downcase
+      end
 
       m.reply "#{nick}'s score is: #{score}    Rank: #{rank}    Jokers: #{jokers}"
     else
@@ -313,45 +315,41 @@ class QuizPlugin < Plugin
       stats = q.registry[nick]
 
       # Find player in table
-      found_player = false
-      i = 0
-      q.rank_table.each_index do |i|
-        if nick.downcase == q.rank_table[i][0].downcase
-          found_player = true
+      old_rank = nil
+      q.rank_table.each_with_index do |place, i|
+        if nick.downcase == place[0].downcase
+          old_rank = i
           break
         end
       end
 
       # Remove player from old position
-      if found_player
-        old_rank = i
-        q.rank_table.delete_at( i )
-      else
-        old_rank = nil
+      if old_rank
+        q.rank_table.delete_at( old_rank )
       end
 
       # Insert player at new position
-      inserted = false
-      q.rank_table.each_index do |i|
-        if stats.score > q.rank_table[i][1].score
+      new_rank = nil
+      q.rank_table.each_with_index do |place, i|
+        if stats.score > place[1].score
           q.rank_table[i,0] = [[nick, stats]]
-          inserted = true
+          new_rank = i
           break
         end
       end
 
       # If less than all other players' scores, append to table
-      unless inserted
-        i += 1 unless q.rank_table.empty?
+      unless new_rank
+        new_rank = q.rank_table.length
         q.rank_table << [nick, stats]
       end
 
       # Print congratulations/condolences if the player's rank has changed
-      unless old_rank.nil?
-        if i < old_rank
-          m.reply "#{nick} ascends to rank #{i + 1}. Congratulations :)"
-        elsif i > old_rank
-          m.reply "#{nick} slides down to rank #{i + 1}. So Sorry! NOT. :p"
+      if old_rank
+        if new_rank < old_rank
+          m.reply "#{nick} ascends to rank #{new_rank + 1}. Congratulations :)"
+        elsif new_rank > old_rank
+          m.reply "#{nick} slides down to rank #{new_rank + 1}. So Sorry! NOT. :p"
         end
       end
     else
index 751543623313faeca00c1d8a47246fac228b32f6..ab0ea161e44cd7885a7cbf800e3aa40874804524 100644 (file)
@@ -772,9 +772,9 @@ class UnoGame
       }
       return false
     end
-    if p = get_player(user)
+    if pl = get_player(user)
       announce _("%{p} is already playing %{uno} here") % {
-        :p => p, :uno => UNO
+        :p => pl, :uno => UNO
       }
       return false
     end
@@ -831,12 +831,12 @@ class UnoGame
       deal(p, @picker)
       @picker = 0
     end
-    score = @players.inject(0) do |sum, p|
-      if p.cards.length > 0
+    score = @players.inject(0) do |sum, pl|
+      if pl.cards.length > 0
         announce _("%{p} still had %{cards}") % {
-          :p => p, :cards => p.cards.join(' ')
+          :p => pl, :cards => pl.cards.join(' ')
         }
-        sum += p.cards.inject(0) do |cs, c|
+        sum += pl.cards.inject(0) do |cs, c|
           cs += c.score
         end
       end
index c67f1095bf19522fdf9d9f8a1b60463f5068f7a5..c76310d5b553fcb417a977b83dcd32e15d50b9cf 100755 (executable)
@@ -70,6 +70,12 @@ module ::GeoIP
     end
   end
 
+  JUMP_TABLE = {
+    "ipinfodb" => Proc.new { |ip| ipinfodb(ip) },
+    "kapsi" => Proc.new { |ip| kapsi(ip) },
+    "geoiptool" => Proc.new { |ip| geoiptool(ip) },
+  }
+
   def self.resolve(hostname, api)
     raise InvalidHostError unless valid_host?(hostname)
 
@@ -79,15 +85,9 @@ module ::GeoIP
       raise InvalidHostError
     end
 
-    jump_table = {
-        "ipinfodb" => Proc.new { |ip| ipinfodb(ip) },
-        "kapsi" => Proc.new { |ip| kapsi(ip) },
-        "geoiptool" => Proc.new { |ip| geoiptool(ip) },
-    }
-
-    raise BadAPIError unless jump_table.key?(api)
+    raise BadAPIError unless JUMP_TABLE.key?(api)
 
-    return jump_table[api].call(ip)
+    return JUMP_TABLE[api].call(ip)
   end
 end
 
@@ -153,7 +153,7 @@ class GeoIpPlugin < Plugin
       if m.replyto.class == Channel
 
         # check if there is an user on the channel with nick same as input given
-        user = m.replyto.users.find { |user| user.nick == params[:input] }
+        user = m.replyto.users.find { |usr| usr.nick == params[:input] }
 
         if user
           m.reply host2output(user.host, user.nick)
index a12b77843073cbed34f71f850b0dd96add8f9dfe..e1209124252026450909a42df81c7e9499913b0c 100644 (file)
@@ -309,8 +309,8 @@ class Imdb
       }
     end
 
-    urls.map { |url|
-      info = info_name(url, :movies_by_year => true)
+    urls.map { |u|
+      info = info_name(u, :movies_by_year => true)
 
       debug info.inspect
 
index 495aa614f61f5657e2be379c0eeec159f04248b9..65867a501db399d42550dafc7077319488f3f8b5 100644 (file)
@@ -116,12 +116,12 @@ module ArinWhois
     def get_parsed_data
       return unless chunks = parse_chunks
 
-      results = split_array_at(parse_chunks) {|chunk|chunk.customer?}
-      results.map do |chunks|
+      results = split_array_at(chunks) {|chunk|chunk.customer?}
+      results.map do |data|
         {
-          :customer => chunks.select{|x|x.customer?}[0],
-          :net      => chunks.select{|x|x.network?}[0],
-          :contacts => chunks.select{|x|x.contact?}
+          :customer => data.select{|x|x.customer?}[0],
+          :net      => data.select{|x|x.network?}[0],
+          :contacts => data.select{|x|x.contact?}
         }
       end
     end
index 2e4c51147b8ba7d888612b87de450a5040b96d6d..4255e8a5306dcf9048366a7eeba02368ce95fe2f 100644 (file)
@@ -194,11 +194,11 @@ class LastFmPlugin < Plugin
     elsif venue
       begin
         venues = search_venue_by(:name => venue.to_s, :limit => 1)
-      rescue Exception => e
-        error e
+      rescue Exception => err
+        error err
         m.reply _("an error occurred looking for venue %{venue}: %{e}") % {
           :venue => venue.to_s,
-          :e => e.message
+          :e => err.message
         }
       end
 
@@ -453,11 +453,11 @@ class LastFmPlugin < Plugin
     if results > 0
       begin
         hits = []
-        doc.root.each_element("results/trackmatches/track") do |track|
+        doc.root.each_element("results/trackmatches/track") do |trck|
           hits << _("%{bold}%{t}%{bold} by %{bold}%{a}%{bold} (%{n} listeners)") % {
-            :t => track.elements["name"].text,
-            :a => track.elements["artist"].text,
-            :n => track.elements["listeners"].text,
+            :t => trck.elements["name"].text,
+            :a => trck.elements["artist"].text,
+            :n => trck.elements["listeners"].text,
             :bold => Bold
           }
         end
@@ -608,8 +608,8 @@ class LastFmPlugin < Plugin
     begin
       res = @bot.httputil.get_response(uri)
       raise _("no response body") unless res.body
-    rescue Exception => e
-        m.reply _("I had problems accessing last.fm: %{e}") % {:e => e.message}
+    rescue Exception => err
+        m.reply _("I had problems accessing last.fm: %{e}") % {:e => err.message}
         return
     end
     doc = Document.new(res.body)
index 6b16361984d3d19056e6e2151316558b396da6c8..4280c52ac4018132a571bcc3484c221d9fcaf561 100644 (file)
@@ -935,8 +935,8 @@ class RSSFeedsPlugin < Plugin
       stop_watches
 
       # Read watches from list.
-      watchlist.each{ |handle, feed|
-        watchRss(feed, m)
+      watchlist.each{ |hndl, fd|
+        watchRss(fd, m)
       }
       m.okay if m
     end
index 69f1566f7245f5db4a37a94061a8156db2bd5df9..2c4a23618b8c91d8f551f53e2dd13b855c9befb5 100644 (file)
@@ -75,9 +75,9 @@ class SlashdotPlugin < Plugin
     debug xml.inspect
     begin
       doc = Document.new xml
-    rescue REXML::ParseException => e
-      warning e.inspect
-      m.reply "couldn't parse output XML: #{e.class}"
+    rescue REXML::ParseException => err
+      warning err.inspect
+      m.reply "couldn't parse output XML: #{err.class}"
       return
     end
     unless doc
index 6c10ed4bfedb3e69b40307df8b0cbbeba04a1cc4..d66883060ea823dcaa394a4362dff6cef53c5460 100644 (file)
@@ -34,7 +34,7 @@ class UrbanPlugin < Plugin
     return m.reply("#{Bold}#{word}#{Bold} not found") if rv.empty?
 
     if notfound
-      suggestions = rv.map { |s| Underline + s[1] + Underline }.uniq.join ', '
+      suggestions = rv.map { |str| Underline + str[1] + Underline }.uniq.join ', '
       m.reply "#{Bold}#{word}#{Bold} not found. maybe you mean #{suggestions}?"
       return
     end
index f7e41d972f55b1f9b6583664e0b727c49143128c..4e93beb4cb39c3ab9661fd2992f0f95072b8f705 100644 (file)
@@ -90,8 +90,8 @@ class Bot
       #
       def initialize(cmd)
         cmdpath = sanitize_command_path(cmd).split('::')
-        seq = cmdpath.inject(["*"]) { |list, cmd|
-          list << (list.length > 1 ? list.last + "::" : "") + cmd
+        seq = cmdpath.inject(["*"]) { |list, cc|
+          list << (list.length > 1 ? list.last + "::" : "") + cc
         }
         @path = seq.map { |k|
           k.to_sym
index 30f99ecf20171183ca826a5b4d1a3895f31ce5ca..465f8f5d870658214bc4b82fad6fada4d2ae0e7c 100644 (file)
@@ -713,7 +713,7 @@ class AuthModule < CoreBotModule
 
   def auth_list_users(m, params)
     # TODO name regexp to filter results
-    list = @bot.auth.save_array.inject([]) { |list, x| ['everyone', 'owner'].include?(x[:username]) ? list : list << x[:username] }
+    list = @bot.auth.save_array.inject([]) { |lst, x| ['everyone', 'owner'].include?(x[:username]) ? lst : lst << x[:username] }
     if defined?(@destroy_q)
       list.map! { |x|
         @destroy_q.include?(x) ? x + _(" (queued for destruction)") : x
index 463e6f383ab2037382b36298a0197f3a946f7980..d188aa3f881e3e9c37a4f029624a4b06dcf1d1ce 100644 (file)
@@ -177,10 +177,10 @@ module ::Irc
         def load_filters(options={})
           case options[:path]
           when nil
-            file = "#{self.dirname}.rb"
+            us = "#{self.dirname}.rb"
             paths = [
-              File.join(Config::datadir, 'filters', file),
-              @bot.path('filters', file)
+              File.join(Config::datadir, 'filters', us),
+              @bot.path('filters', us)
             ]
           when Array
             paths = options[:path]
index 25df3c5ba86afa660219bacf9ca1ec36e845d124..03671cfea060da9a60d6ebb53694bdc7f5cb20ce 100644 (file)
@@ -531,8 +531,6 @@ class HttpUtil
       :method => :GET
     }.merge(options)
 
-    resp = nil
-
     req_class = case opts[:method].to_s.downcase.intern
                 when :head, :"net::http::head"
                   opts[:max_redir] = -1
index 4e624f9b4e80b9d0aa64a00855ee4c72c5913894..81d7d775ef329f4058531cdb8444365a2d87a0a4 100755 (executable)
@@ -14,10 +14,10 @@ class Wordlist
     @@wordlist_base ||= Utils.bot.path 'wordlists'
   end
 
-  def self.get(path, options={})
+  def self.get(where, options={})
     opts = { :spaces => false }.merge(options)
 
-    wordlist_path = File.join(wordlist_base, path)
+    wordlist_path = File.join(wordlist_base, where)
     raise "wordlist not found: #{wordlist_path}" unless File.exist?(wordlist_path)
 
     # Location is a directory -> combine all lists beneath it