Skip to content

Commit

Permalink
Merge pull request #35121 from utilum/warning_tried_to_create_proc_wi…
Browse files Browse the repository at this point in the history
…thout_block

Ruby 2.7 warning: creating a Proc without a block
  • Loading branch information
kaspth committed Mar 10, 2019
2 parents 08a93ef + c99e673 commit c87f684
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions actionmailer/lib/action_mailer/base.rb
Expand Up @@ -944,9 +944,9 @@ def assign_headers_to_message(message, headers)
assignable.each { |k, v| message[k] = v }
end

def collect_responses(headers)
def collect_responses(headers, &block)
if block_given?
collect_responses_from_block(headers, &Proc.new)
collect_responses_from_block(headers, &block)
elsif headers[:body]
collect_responses_from_text(headers)
else
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_controller/metal.rb
Expand Up @@ -26,10 +26,10 @@ def valid?(action)
end
end

def build(action, app = Proc.new)
def build(action, app = nil, &block)
action = action.to_s

middlewares.reverse.inject(app) do |a, middleware|
middlewares.reverse.inject(app || block) do |a, middleware|
middleware.valid?(action) ? middleware.build(a) : a
end
end
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_dispatch/middleware/stack.rb
Expand Up @@ -97,8 +97,8 @@ def use(klass, *args, &block)
middlewares.push(build_middleware(klass, args, block))
end

def build(app = Proc.new)
middlewares.freeze.reverse.inject(app) { |a, e| e.build(a) }
def build(app = nil, &block)
middlewares.freeze.reverse.inject(app || block) { |a, e| e.build(a) }
end

private
Expand Down
4 changes: 2 additions & 2 deletions actionview/lib/action_view/helpers/form_helper.rb
Expand Up @@ -739,7 +739,7 @@ def apply_form_for_options!(record, object, options) #:nodoc:
# def labelled_form_with(**options, &block)
# form_with(**options.merge(builder: LabellingFormBuilder), &block)
# end
def form_with(model: nil, scope: nil, url: nil, format: nil, **options)
def form_with(model: nil, scope: nil, url: nil, format: nil, **options, &block)
options[:allow_method_names_outside_object] = true
options[:skip_default_ids] = !form_with_generates_ids

Expand All @@ -752,7 +752,7 @@ def form_with(model: nil, scope: nil, url: nil, format: nil, **options)

if block_given?
builder = instantiate_builder(scope, model, options)
output = capture(builder, &Proc.new)
output = capture(builder, &block)
options[:multipart] ||= builder.multipart?

html_options = html_options_for_form_with(url, model, options)
Expand Down
Expand Up @@ -20,10 +20,10 @@ def self.define_callbacks(model, reflection)
}
end

def self.define_extensions(model, name)
def self.define_extensions(model, name, &block)
if block_given?
extension_module_name = "#{model.name.demodulize}#{name.to_s.camelize}AssociationExtension"
extension = Module.new(&Proc.new)
extension = Module.new(&block)
model.module_parent.const_set(extension_module_name, extension)
end
end
Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/scoping/default.rb
Expand Up @@ -86,8 +86,8 @@ def before_remove_const #:nodoc:
# # Should return a scope, you can call 'super' here etc.
# end
# end
def default_scope(scope = nil) # :doc:
scope = Proc.new if block_given?
def default_scope(scope = nil, &block) # :doc:
scope = block if block_given?

if scope.is_a?(Relation) || !scope.respond_to?(:call)
raise ArgumentError,
Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/statement_cache.rb
Expand Up @@ -113,8 +113,8 @@ def bind(values)
end
end

def self.create(connection, block = Proc.new)
relation = block.call Params.new
def self.create(connection, callable = nil, &block)
relation = (callable || block).call Params.new
query_builder, binds = connection.cacheable_query(self, relation.arel)
bind_map = BindMap.new(binds)
new(query_builder, bind_map, relation.klass)
Expand Down
4 changes: 2 additions & 2 deletions activesupport/lib/active_support/notifications/fanout.rb
Expand Up @@ -20,8 +20,8 @@ def initialize
super
end

def subscribe(pattern = nil, block = Proc.new)
subscriber = Subscribers.new pattern, block
def subscribe(pattern = nil, callable = nil, &block)
subscriber = Subscribers.new(pattern, callable || block)
synchronize do
if String === pattern
@string_subscribers[pattern] << subscriber
Expand Down
4 changes: 2 additions & 2 deletions railties/lib/rails/engine.rb
Expand Up @@ -530,9 +530,9 @@ def env_config

# Defines the routes for this engine. If a block is given to
# routes, it is appended to the engine.
def routes
def routes(&block)
@routes ||= ActionDispatch::Routing::RouteSet.new_with_config(config)
@routes.append(&Proc.new) if block_given?
@routes.append(&block) if block_given?
@routes
end

Expand Down

0 comments on commit c87f684

Please sign in to comment.