Permalink
Browse files

avoid needless creation/allocation of many variables

Especially in blocks, using either understore notation, or by using
each_value instead of each.
  • Loading branch information...
kabaka committed Dec 14, 2015
1 parent eb48bab commit 3ecc3de43de1bb8a4890b053321704e63666099a
View
@@ -151,7 +151,7 @@ def self.delete_alias cmd
# Delete all aliases which reference `target` command.
# @param target [String] command for which to delete aliases
def self.delete_aliases_for target
ALIASES.reject! do |a, t|
ALIASES.reject! do |_, t|
t == target
end
View
@@ -99,8 +99,8 @@ def dispatch_for owner, name, msg = nil, data = {}
#
# @param owner [Object]
def delete_for owner
self.each do |n, a|
a.delete_if {|e| e.owner == owner}
self.each_value do |array|
array.delete_if { |event| event.owner == owner }
end
end
@@ -152,7 +152,7 @@ def dispatch owner, name, func, msg = nil, data = {}, &blk
# @param name [Symbol]
# @param msg [String]
# @param data [Hash]
def initialize owner, name, msg = nil, data = {}
def initialize owner, _name, msg = nil, data = {}
super owner, msg, nil, '', data
end
end
View
@@ -40,7 +40,7 @@ def add_handler parent, regex, &block
end
def delete_for parent
@@handlers.reject! do |regex, handlers|
@@handlers.reject! do |_regex, handlers|
handlers.reject! do |handler|
handler[:owner] == parent
end
View
@@ -53,7 +53,7 @@ def add_handler parent, regex = nil, &block
end
def delete_for parent
@@handlers.reject! do |regex, handler|
@@handlers.reject! do |_regex, handler|
handler[:owner] == parent
end
View
@@ -138,8 +138,8 @@
# if they are logged in, update the live data too
Connections.each do |name, conn|
conn.users.each do |nick, user|
Connections.each do |_ conn|
conn.users.each do |_, user|
if user.account == @params[0]
user.level = level
end
View
@@ -41,7 +41,7 @@
# to see the JOIN events we need to start the loggers. So we have to do
# it the hard way, just in case.
Bot::Connections.each do |name, connection|
Bot::Connections.each_value do |connection|
connection.channels.each_key do |channel|
new_logger connection.name, channel
end
@@ -80,7 +80,7 @@ def new_logger network, channel
@@loggers[network][channel] = Logger.new "#{@@log_dir}#{network}.#{channel}.log"
@@loggers[network][channel].formatter = proc do |severity, datetime, progname, msg|
@@loggers[network][channel].formatter = proc do |_severity, datetime, progname, msg|
"#{datetime}\t#{progname}\t#{msg}\n"
end
View
@@ -93,7 +93,7 @@ def rot_decode key, data
def xor_core key, data
key_it = key.chars.cycle
data.each_char.map.each_with_index { |c, i|
data.each_char.map.each { |c|
(c.ord ^ key_it.next.ord).chr
}.join
end
View
@@ -42,7 +42,7 @@
data = json['story']
rating = data['content_rating_text']
cats = data['categories'].select {|k,v| v}.keys.join(', ')
cats = data['categories'].select {|_,v| v}.keys.join(', ')
title = html_decode data['title']
desc = html_decode data['short_description']
View
@@ -58,7 +58,7 @@
helpers do
def top n = 3
karma = get_data(@connection.name, Hash.new(0)).sort_by {|n, k| k}
karma = get_data(@connection.name, Hash.new(0)).sort_by {|_, k| k}
if karma.empty?
return 'Nobody has received karma, yet.'
@@ -68,7 +68,7 @@ def top n = 3
end
def bottom n = 3
karma = get_data(@connection.name, Hash.new(0)).sort_by {|n, k| k}
karma = get_data(@connection.name, Hash.new(0)).sort_by {|_, k| k}
if karma.empty?
return 'Nobody has received karma, yet.'
View
@@ -49,15 +49,15 @@
helpers do
def top n = 3
potassium = get_data(@connection.name, Hash.new(0)).sort_by {|n, k| k}
potassium = get_data(@connection.name, Hash.new(0)).sort_by {|_, k| k}
raise 'Nobody has any potassium, yet.' if potassium.empty?
Hash[potassium.last(n).reverse]
end
def bottom n = 3
potassium = get_data(@connection.name, Hash.new(0)).sort_by {|n, k| k}
potassium = get_data(@connection.name, Hash.new(0)).sort_by {|_, k| k}
raise 'Nobody has any potassium, yet.' if potassium.empty?
View
@@ -33,7 +33,7 @@
lines_received, lines_sent = 0, 0
bytes_received, bytes_sent = 0, 0
Bot::Connections.each do |name, connection|
Bot::Connections.each_value do |connection|
lines_received += connection.lines_received
bytes_received += connection.bytes_received
lines_sent += connection.lines_sent
View
@@ -48,13 +48,13 @@
credit = root.elements['//credit'].text
updatedTime = root.elements['//observation_epoch'].text.to_i
localTime = root.elements['//local_time'].text
#localTime = root.elements['//local_time'].text
stationLocation = root.elements['//observation_location/full'].text
temperature = root.elements['//temperature_string'].text
humidity = root.elements['//relative_humidity'].text
wind = root.elements['//wind_string'].text
pressure = root.elements['//pressure_string'].text
dewpoint = root.elements['//dewpoint_string'].text
#pressure = root.elements['//pressure_string'].text
#dewpoint = root.elements['//dewpoint_string'].text
link = root.elements['//forecast_url'].text
updated = "#{Time.at(updatedTime).to_fuzzy_duration_s} ago"
View
@@ -62,7 +62,7 @@ OptionParser.new do |opts|
end
$opts[:fork] = true
opts.on '-f', '--no-fork', 'Don\'t run in the background' do |v|
opts.on '-f', '--no-fork', 'Don\'t run in the background' do
$opts[:fork] = false
end

0 comments on commit 3ecc3de

Please sign in to comment.