Use Object#tap instead of #returning (#6887).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4406 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2010-11-14 16:24:21 +00:00
parent c4a218358f
commit 2ee45e8cac
6 changed files with 8 additions and 8 deletions

View File

@ -57,7 +57,7 @@ module Redmine
# Calls a hook. # Calls a hook.
# Returns the listeners response. # Returns the listeners response.
def call_hook(hook, context={}) def call_hook(hook, context={})
returning [] do |response| [].tap do |response|
hls = hook_listeners(hook) hls = hook_listeners(hook)
if hls.any? if hls.any?
hls.each {|listener| response << listener.send(hook, context)} hls.each {|listener| response << listener.send(hook, context)}

View File

@ -192,13 +192,13 @@ module Redmine
def render_menu_node_with_children(node, project=nil) def render_menu_node_with_children(node, project=nil)
caption, url, selected = extract_node_details(node, project) caption, url, selected = extract_node_details(node, project)
html = returning [] do |html| html = [].tap do |html|
html << '<li>' html << '<li>'
# Parent # Parent
html << render_single_menu_node(node, caption, url, selected) html << render_single_menu_node(node, caption, url, selected)
# Standard children # Standard children
standard_children_list = returning "" do |child_html| standard_children_list = "".tap do |child_html|
node.children.each do |child| node.children.each do |child|
child_html << render_menu_node(child, project) child_html << render_menu_node(child, project)
end end
@ -219,7 +219,7 @@ module Redmine
def render_unattached_children_menu(node, project) def render_unattached_children_menu(node, project)
return nil unless node.child_menus return nil unless node.child_menus
returning "" do |child_html| "".tap do |child_html|
unattached_children = node.child_menus.call(project) unattached_children = node.child_menus.call(project)
# Tree nodes support #each so we need to do object detection # Tree nodes support #each so we need to do object detection
if unattached_children.is_a? Array if unattached_children.is_a? Array

View File

@ -18,7 +18,7 @@ class Project < ActiveRecord::Base
end end
def self.all_modules def self.all_modules
returning [] do |modules| [].tap do |modules|
Redmine::AccessControl.available_project_modules.each do |name| Redmine::AccessControl.available_project_modules.each do |name|
modules << EnabledModule.new(:name => name.to_s) modules << EnabledModule.new(:name => name.to_s)
end end

View File

@ -154,7 +154,7 @@ module CollectiveIdea #:nodoc:
def each_root_valid?(roots_to_validate) def each_root_valid?(roots_to_validate)
left = right = 0 left = right = 0
roots_to_validate.all? do |root| roots_to_validate.all? do |root|
returning(root.left > left && root.right > right) do (root.left > left && root.right > right).tap do
left = root.left left = root.left
right = root.right right = root.right
end end

View File

@ -76,7 +76,7 @@ class PluginMigrationGenerator < Rails::Generator::Base
# plugin names involved is shorter than 230 characters that one will be # plugin names involved is shorter than 230 characters that one will be
# used. Otherwise a shorter name will be returned. # used. Otherwise a shorter name will be returned.
def build_migration_name def build_migration_name
returning descriptive_migration_name do |name| descriptive_migration_name.tap do |name|
name.replace short_migration_name if name.length > MAX_FILENAME_LENGTH name.replace short_migration_name if name.length > MAX_FILENAME_LENGTH
end end
end end

View File

@ -71,7 +71,7 @@ module GravatarHelper
email_hash = Digest::MD5.hexdigest(email) email_hash = Digest::MD5.hexdigest(email)
options = DEFAULT_OPTIONS.merge(options) options = DEFAULT_OPTIONS.merge(options)
options[:default] = CGI::escape(options[:default]) unless options[:default].nil? options[:default] = CGI::escape(options[:default]) unless options[:default].nil?
returning gravatar_api_url(email_hash, options.delete(:ssl)) do |url| gravatar_api_url(email_hash, options.delete(:ssl)).tap do |url|
opts = [] opts = []
[:rating, :size, :default].each do |opt| [:rating, :size, :default].each do |opt|
unless options[opt].nil? unless options[opt].nil?