Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Pass symbol as an argument instead of a block
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Nov 29, 2014
1 parent 56e47cf commit d1374f9
Show file tree
Hide file tree
Showing 120 changed files with 244 additions and 276 deletions.
4 changes: 2 additions & 2 deletions actionmailer/lib/action_mailer/base.rb
Expand Up @@ -859,7 +859,7 @@ def set_content_type(m, user_content_type, class_default)
when user_content_type.present?
user_content_type
when m.has_attachments?
if m.attachments.detect { |a| a.inline? }
if m.attachments.detect(&:inline?)
["multipart", "related", params]
else
["multipart", "mixed", params]
Expand Down Expand Up @@ -914,7 +914,7 @@ def each_template(paths, name, &block) #:nodoc:
if templates.empty?
raise ActionView::MissingTemplate.new(paths, name, paths, false, 'mailer')
else
templates.uniq { |t| t.formats }.each(&block)
templates.uniq(&:formats).each(&block)
end
end

Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/abstract_controller/base.rb
Expand Up @@ -82,7 +82,7 @@ def action_methods
# Except for public instance methods of Base and its ancestors
internal_methods +
# Be sure to include shadowed public instance methods of this class
public_instance_methods(false)).uniq.map { |x| x.to_s } -
public_instance_methods(false)).uniq.map(&:to_s) -
# And always exclude explicitly hidden actions
hidden_actions.to_a

Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/metal/testing.rb
Expand Up @@ -24,7 +24,7 @@ def recycle!

module ClassMethods
def before_filters
_process_action_callbacks.find_all{|x| x.kind == :before}.map{|x| x.name}
_process_action_callbacks.find_all{|x| x.kind == :before}.map(&:name)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/http/mime_type.rb
Expand Up @@ -6,7 +6,7 @@
module Mime
class Mimes < Array
def symbols
@symbols ||= map { |m| m.to_sym }
@symbols ||= map(&:to_sym)
end

%w(<< concat shift unshift push pop []= clear compact! collect!
Expand Down
Expand Up @@ -107,7 +107,7 @@ def move(t, a)
end

def alphabet
inverted.values.flat_map(&:keys).compact.uniq.sort_by { |x| x.to_s }
inverted.values.flat_map(&:keys).compact.uniq.sort_by(&:to_s)
end

# Returns a set of NFA states reachable from some NFA state +s+ in set
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_dispatch/journey/path/pattern.rb
Expand Up @@ -42,7 +42,7 @@ def ast
end

def names
@names ||= spec.grep(Nodes::Symbol).map { |n| n.name }
@names ||= spec.grep(Nodes::Symbol).map(&:name)
end

def required_names
Expand All @@ -52,7 +52,7 @@ def required_names
def optional_names
@optional_names ||= spec.grep(Nodes::Group).flat_map { |group|
group.grep(Nodes::Symbol)
}.map { |n| n.name }.uniq
}.map(&:name).uniq
end

class RegexpOffsets < Journey::Visitors::Visitor # :nodoc:
Expand Down
6 changes: 3 additions & 3 deletions actionpack/lib/action_dispatch/journey/route.rb
Expand Up @@ -60,7 +60,7 @@ def score(constraints)
end

def parts
@parts ||= segments.map { |n| n.to_sym }
@parts ||= segments.map(&:to_sym)
end
alias :segment_keys :parts

Expand All @@ -69,11 +69,11 @@ def format(path_options)
end

def optional_parts
path.optional_names.map { |n| n.to_sym }
path.optional_names.map(&:to_sym)
end

def required_parts
@required_parts ||= path.required_names.map { |n| n.to_sym }
@required_parts ||= path.required_names.map(&:to_sym)
end

def required_default?(key)
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_dispatch/journey/router.rb
Expand Up @@ -68,8 +68,8 @@ def recognize(rails_req)

def visualizer
tt = GTG::Builder.new(ast).transition_table
groups = partitioned_routes.first.map(&:ast).group_by { |a| a.to_s }
asts = groups.values.map { |v| v.first }
groups = partitioned_routes.first.map(&:ast).group_by(&:to_s)
asts = groups.values.map(&:first)
tt.visualizer(asts)
end

Expand Down
4 changes: 1 addition & 3 deletions actionpack/lib/action_dispatch/routing/inspector.rb
Expand Up @@ -114,9 +114,7 @@ def filter_routes(filter)
def collect_routes(routes)
routes.collect do |route|
RouteWrapper.new(route)
end.reject do |route|
route.internal?
end.collect do |route|
end.reject(&:internal?).collect do |route|
collect_engine_routes(route)

{ name: route.name,
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_dispatch/routing/route_set.rb
Expand Up @@ -543,7 +543,7 @@ def add_route(app, conditions = {}, requirements = {}, defaults = {}, name = nil
path = conditions.delete :path_info
ast = conditions.delete :parsed_path_info
path = build_path(path, ast, requirements, anchor)
conditions = build_conditions(conditions, path.names.map { |x| x.to_sym })
conditions = build_conditions(conditions, path.names.map(&:to_sym))

route = @set.add_route(app, path, conditions, defaults, name)
named_routes[name] = route if name
Expand Down Expand Up @@ -605,7 +605,7 @@ class Generator #:nodoc:
if name == :controller
value
elsif value.is_a?(Array)
value.map { |v| v.to_param }.join('/')
value.map(&:to_param).join('/')
elsif param = value.to_param
param
end
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/testing/test_request.rb
Expand Up @@ -60,7 +60,7 @@ def user_agent=(user_agent)

def accept=(mime_types)
@env.delete('action_dispatch.request.accepts')
@env['HTTP_ACCEPT'] = Array(mime_types).collect { |mime_type| mime_type.to_s }.join(",")
@env['HTTP_ACCEPT'] = Array(mime_types).collect(&:to_s).join(",")
end

alias :rack_cookies :cookies
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/abstract_unit.rb
Expand Up @@ -53,7 +53,7 @@ def env
# Register danish language for testing
I18n.backend.store_translations 'da', {}
I18n.backend.store_translations 'pt-BR', {}
ORIGINAL_LOCALES = I18n.available_locales.map {|locale| locale.to_s }.sort
ORIGINAL_LOCALES = I18n.available_locales.map(&:to_s).sort

FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
FIXTURES = Pathname.new(FIXTURE_LOAD_PATH)
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/filters_test.rb
Expand Up @@ -10,7 +10,7 @@ class << self

def before_actions
filters = _process_action_callbacks.select { |c| c.kind == :before }
filters.map! { |c| c.raw_filter }
filters.map!(&:raw_filter)
end
end

Expand Down
8 changes: 4 additions & 4 deletions actionpack/test/controller/routing_test.rb
Expand Up @@ -884,13 +884,13 @@ def test_generate_extras
set.draw { get ':controller/(:action(/:id))' }
path, extras = set.generate_extras(:controller => "foo", :action => "bar", :id => 15, :this => "hello", :that => "world")
assert_equal "/foo/bar/15", path
assert_equal %w(that this), extras.map { |e| e.to_s }.sort
assert_equal %w(that this), extras.map(&:to_s).sort
end

def test_extra_keys
set.draw { get ':controller/:action/:id' }
extras = set.extra_keys(:controller => "foo", :action => "bar", :id => 15, :this => "hello", :that => "world")
assert_equal %w(that this), extras.map { |e| e.to_s }.sort
assert_equal %w(that this), extras.map(&:to_s).sort
end

def test_generate_extras_not_first
Expand All @@ -900,7 +900,7 @@ def test_generate_extras_not_first
end
path, extras = set.generate_extras(:controller => "foo", :action => "bar", :id => 15, :this => "hello", :that => "world")
assert_equal "/foo/bar/15", path
assert_equal %w(that this), extras.map { |e| e.to_s }.sort
assert_equal %w(that this), extras.map(&:to_s).sort
end

def test_generate_not_first
Expand All @@ -918,7 +918,7 @@ def test_extra_keys_not_first
get ':controller/:action/:id'
end
extras = set.extra_keys(:controller => "foo", :action => "bar", :id => 15, :this => "hello", :that => "world")
assert_equal %w(that this), extras.map { |e| e.to_s }.sort
assert_equal %w(that this), extras.map(&:to_s).sort
end

def test_draw
Expand Down
4 changes: 2 additions & 2 deletions actionpack/test/dispatch/mime_type_test.rb
Expand Up @@ -83,15 +83,15 @@ class MimeTypeTest < ActiveSupport::TestCase
test "parse broken acceptlines" do
accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/*,,*/*;q=0.5"
expect = [Mime::HTML, Mime::XML, "image/*", Mime::TEXT, Mime::ALL]
assert_equal expect, Mime::Type.parse(accept).collect { |c| c.to_s }
assert_equal expect, Mime::Type.parse(accept).collect(&:to_s)
end

# Accept header send with user HTTP_USER_AGENT: Mozilla/4.0
# (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1)
test "parse other broken acceptlines" do
accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, , pronto/1.00.00, sslvpn/1.00.00.00, */*"
expect = ['image/gif', 'image/x-xbitmap', 'image/jpeg','image/pjpeg', 'application/x-shockwave-flash', 'application/vnd.ms-excel', 'application/vnd.ms-powerpoint', 'application/msword', 'pronto/1.00.00', 'sslvpn/1.00.00.00', Mime::ALL]
assert_equal expect, Mime::Type.parse(accept).collect { |c| c.to_s }
assert_equal expect, Mime::Type.parse(accept).collect(&:to_s)
end

test "custom type" do
Expand Down
2 changes: 1 addition & 1 deletion actionview/lib/action_view/helpers/date_helper.rb
Expand Up @@ -898,7 +898,7 @@ def date_order

def translated_date_order
date_order = I18n.translate(:'date.order', :locale => @options[:locale], :default => [])
date_order = date_order.map { |element| element.to_sym }
date_order = date_order.map(&:to_sym)

forbidden_elements = date_order - [:year, :month, :day]
if forbidden_elements.any?
Expand Down
4 changes: 2 additions & 2 deletions actionview/lib/action_view/helpers/form_options_helper.rb
Expand Up @@ -351,12 +351,12 @@ def options_for_select(container, selected = nil)
return container if String === container

selected, disabled = extract_selected_and_disabled(selected).map do |r|
Array(r).map { |item| item.to_s }
Array(r).map(&:to_s)
end

container.map do |element|
html_attributes = option_html_attributes(element)
text, value = option_text_and_value(element).map { |item| item.to_s }
text, value = option_text_and_value(element).map(&:to_s)

html_attributes[:selected] ||= option_value_selected?(value, selected)
html_attributes[:disabled] ||= disabled && option_value_selected?(value, disabled)
Expand Down
2 changes: 1 addition & 1 deletion actionview/lib/action_view/helpers/tag_helper.rb
Expand Up @@ -18,7 +18,7 @@ module TagHelper
itemscope allowfullscreen default inert sortable
truespeed typemustmatch).to_set

BOOLEAN_ATTRIBUTES.merge(BOOLEAN_ATTRIBUTES.map {|attribute| attribute.to_sym })
BOOLEAN_ATTRIBUTES.merge(BOOLEAN_ATTRIBUTES.map(&:to_sym))

TAG_PREFIXES = ['aria', 'data', :aria, :data].to_set

Expand Down
2 changes: 1 addition & 1 deletion actionview/lib/action_view/layouts.rb
Expand Up @@ -262,7 +262,7 @@ def _conditional_layout?
def layout(layout, conditions = {})
include LayoutConditions unless conditions.empty?

conditions.each {|k, v| conditions[k] = Array(v).map {|a| a.to_s} }
conditions.each {|k, v| conditions[k] = Array(v).map(&:to_s) }
self._layout_conditions = conditions

self._layout = layout
Expand Down
2 changes: 1 addition & 1 deletion actionview/lib/action_view/template/error.rb
Expand Up @@ -75,7 +75,7 @@ def file_name
def sub_template_message
if @sub_templates
"Trace of template inclusion: " +
@sub_templates.collect { |template| template.inspect }.join(", ")
@sub_templates.collect(&:inspect).join(", ")
else
""
end
Expand Down
2 changes: 1 addition & 1 deletion actionview/lib/action_view/template/handlers.rb
Expand Up @@ -42,7 +42,7 @@ def unregister_template_handler(*extensions)
end

def template_handler_extensions
@@template_handlers.keys.map {|key| key.to_s }.sort
@@template_handlers.keys.map(&:to_s).sort
end

def registered_template_handler(extension)
Expand Down
2 changes: 1 addition & 1 deletion actionview/lib/action_view/template/resolver.rb
Expand Up @@ -139,7 +139,7 @@ def build_path(name, prefix, partial)
# resolver is fresher before returning it.
def cached(key, path_info, details, locals) #:nodoc:
name, prefix, partial = path_info
locals = locals.map { |x| x.to_s }.sort!
locals = locals.map(&:to_s).sort!

if key
@cache.cache(key, name, prefix, partial, locals) do
Expand Down
2 changes: 1 addition & 1 deletion actionview/lib/action_view/template/types.rb
Expand Up @@ -9,7 +9,7 @@ class Type
self.types = Set.new

def self.register(*t)
types.merge(t.map { |type| type.to_s })
types.merge(t.map(&:to_s))
end

register :html, :text, :js, :css, :xml, :json
Expand Down
2 changes: 1 addition & 1 deletion actionview/test/abstract_unit.rb
Expand Up @@ -46,7 +46,7 @@ def env
# Register danish language for testing
I18n.backend.store_translations 'da', {}
I18n.backend.store_translations 'pt-BR', {}
ORIGINAL_LOCALES = I18n.available_locales.map {|locale| locale.to_s }.sort
ORIGINAL_LOCALES = I18n.available_locales.map(&:to_s).sort

FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
FIXTURES = Pathname.new(FIXTURE_LOAD_PATH)
Expand Down
2 changes: 1 addition & 1 deletion actionview/test/actionpack/controller/view_paths_test.rb
Expand Up @@ -39,7 +39,7 @@ def expand(array)

def assert_paths(*paths)
controller = paths.first.is_a?(Class) ? paths.shift : @controller
assert_equal expand(paths), controller.view_paths.map { |p| p.to_s }
assert_equal expand(paths), controller.view_paths.map(&:to_s)
end

def test_template_load_path_was_set_correctly
Expand Down
2 changes: 1 addition & 1 deletion actionview/test/template/erb_util_test.rb
Expand Up @@ -84,7 +84,7 @@ def test_html_escape_passes_html_escape_unmodified
end

def test_rest_in_ascii
(0..127).to_a.map {|int| int.chr }.each do |chr|
(0..127).to_a.map(&:chr).each do |chr|
next if %('"&<>).include?(chr)
assert_equal chr, html_escape(chr)
end
Expand Down
2 changes: 1 addition & 1 deletion actionview/test/template/render_test.rb
Expand Up @@ -16,7 +16,7 @@ def setup_view(paths)
I18n.backend.store_translations 'pt-BR', {}

# Ensure original are still the same since we are reindexing view paths
assert_equal ORIGINAL_LOCALES, I18n.available_locales.map {|l| l.to_s }.sort
assert_equal ORIGINAL_LOCALES, I18n.available_locales.map(&:to_s).sort
end

def test_render_without_options
Expand Down
4 changes: 1 addition & 3 deletions activejob/test/support/delayed_job/delayed/backend/test.rb
Expand Up @@ -43,9 +43,7 @@ def self.delete_all
end

def self.create(attrs = {})
new(attrs).tap do |o|
o.save
end
new(attrs).tap(&:save)
end

def self.create!(*args); create(*args); end
Expand Down
2 changes: 1 addition & 1 deletion activejob/test/support/integration/adapters/sidekiq.rb
Expand Up @@ -48,7 +48,7 @@ def stop_workers

def can_run?
begin
Sidekiq.redis { |conn| conn.connect }
Sidekiq.redis(&:connect)
rescue
return false
end
Expand Down
Expand Up @@ -59,7 +59,7 @@ def test_validates_numericality_of_with_integer_only_and_symbol_as_value

def test_validates_numericality_of_with_integer_only_and_proc_as_value
Topic.send(:define_method, :allow_only_integers?, lambda { false })
Topic.validates_numericality_of :approved, only_integer: Proc.new {|topic| topic.allow_only_integers? }
Topic.validates_numericality_of :approved, only_integer: Proc.new(&:allow_only_integers?)

invalid!(NIL + BLANK + JUNK)
valid!(FLOATS + INTEGERS + BIGDECIMAL + INFINITY)
Expand Down Expand Up @@ -130,7 +130,7 @@ def test_validates_numericality_with_other_than

def test_validates_numericality_with_proc
Topic.send(:define_method, :min_approved, lambda { 5 })
Topic.validates_numericality_of :approved, greater_than_or_equal_to: Proc.new {|topic| topic.min_approved }
Topic.validates_numericality_of :approved, greater_than_or_equal_to: Proc.new(&:min_approved)

invalid!([3, 4])
valid!([5, 6])
Expand Down
2 changes: 1 addition & 1 deletion activemodel/test/cases/validations_test.rb
Expand Up @@ -282,7 +282,7 @@ def test_list_of_validators_on_multiple_attributes
ActiveModel::Validations::FormatValidator,
ActiveModel::Validations::LengthValidator,
ActiveModel::Validations::PresenceValidator
], validators.map { |v| v.class }.sort_by { |c| c.to_s }
], validators.map(&:class).sort_by(&:to_s)
end

def test_list_of_validators_will_be_empty_when_empty
Expand Down
4 changes: 2 additions & 2 deletions activerecord/examples/performance.rb
Expand Up @@ -39,8 +39,8 @@ def self.with_notes
where("notes IS NOT NULL")
end

def self.look(exhibits) exhibits.each { |e| e.look } end
def self.feel(exhibits) exhibits.each { |e| e.feel } end
def self.look(exhibits) exhibits.each(&:look) end
def self.feel(exhibits) exhibits.each(&:feel) end
end

def progress_bar(int); print "." if (int%100).zero? ; end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/associations.rb
Expand Up @@ -57,7 +57,7 @@ def initialize(reflection)
through_reflection = reflection.through_reflection
source_reflection_names = reflection.source_reflection_names
source_associations = reflection.through_reflection.klass._reflections.keys
super("Could not find the source association(s) #{source_reflection_names.collect{ |a| a.inspect }.to_sentence(:two_words_connector => ' or ', :last_word_connector => ', or ', :locale => :en)} in model #{through_reflection.klass}. Try 'has_many #{reflection.name.inspect}, :through => #{through_reflection.name.inspect}, :source => <name>'. Is it one of #{source_associations.to_sentence(:two_words_connector => ' or ', :last_word_connector => ', or ', :locale => :en)}?")
super("Could not find the source association(s) #{source_reflection_names.collect(&:inspect).to_sentence(:two_words_connector => ' or ', :last_word_connector => ', or ', :locale => :en)} in model #{through_reflection.klass}. Try 'has_many #{reflection.name.inspect}, :through => #{through_reflection.name.inspect}, :source => <name>'. Is it one of #{source_associations.to_sentence(:two_words_connector => ' or ', :last_word_connector => ', or ', :locale => :en)}?")
end
end

Expand Down

0 comments on commit d1374f9

Please sign in to comment.