Permalink
Browse files

`self.` is not needed when calling its own instance method

Actually, private methods cannot be called with `self.`, so it's not just redundant, it's a bad habit in Ruby
  • Loading branch information...
1 parent 6197a38 commit 5473e390d362755125d2f47b64ef0a135f2fe111 @amatsuda amatsuda committed Jan 5, 2017
Showing with 71 additions and 71 deletions.
  1. +1 −1 actioncable/lib/action_cable/engine.rb
  2. +2 −2 actioncable/lib/rails/generators/channel/channel_generator.rb
  3. +1 −1 actionmailer/lib/action_mailer/delivery_methods.rb
  4. +1 −1 actionmailer/lib/action_mailer/preview.rb
  5. +1 −1 actionmailer/lib/action_mailer/test_case.rb
  6. +1 −1 actionmailer/lib/rails/generators/mailer/mailer_generator.rb
  7. +1 −1 actionpack/lib/action_controller/metal/head.rb
  8. +1 −1 actionpack/lib/action_controller/metal/rendering.rb
  9. +1 −1 actionpack/lib/action_controller/metal/strong_parameters.rb
  10. +1 −1 actionpack/lib/action_controller/test_case.rb
  11. +2 −2 actionpack/test/controller/integration_test.rb
  12. +1 −1 actionpack/test/controller/url_for_test.rb
  13. +1 −1 actionpack/test/dispatch/routing_test.rb
  14. +1 −1 actionview/lib/action_view/helpers/tags/date_select.rb
  15. +1 −1 actionview/lib/action_view/helpers/tags/text_field.rb
  16. +1 −1 actionview/lib/action_view/layouts.rb
  17. +2 −2 actionview/lib/action_view/test_case.rb
  18. +1 −1 actionview/lib/action_view/view_paths.rb
  19. +1 −1 actionview/test/activerecord/polymorphic_routes_test.rb
  20. +1 −1 activejob/lib/rails/generators/job/job_generator.rb
  21. +1 −1 activejob/test/cases/queue_naming_test.rb
  22. +1 −1 activejob/test/cases/queue_priority_test.rb
  23. +1 −1 activejob/test/support/sneakers/inline.rb
  24. +1 −1 activemodel/lib/active_model/naming.rb
  25. +1 −1 activemodel/lib/active_model/translation.rb
  26. +1 −1 activerecord/lib/active_record/associations.rb
  27. +1 −1 activerecord/lib/active_record/associations/has_many_association.rb
  28. +1 −1 activerecord/lib/active_record/attribute_methods/primary_key.rb
  29. +2 −2 activerecord/lib/active_record/autosave_association.rb
  30. +2 −2 activerecord/lib/active_record/core.rb
  31. +1 −1 activerecord/lib/active_record/fixtures.rb
  32. +3 −3 activerecord/lib/active_record/nested_attributes.rb
  33. +2 −2 activerecord/lib/active_record/railtie.rb
  34. +1 −1 activerecord/lib/active_record/readonly_attributes.rb
  35. +1 −1 activerecord/lib/active_record/relation/batches.rb
  36. +1 −1 activerecord/lib/active_record/relation/calculations.rb
  37. +1 −1 activerecord/lib/active_record/relation/query_methods.rb
  38. +1 −1 activerecord/lib/active_record/sanitization.rb
  39. +1 −1 activerecord/lib/active_record/secure_token.rb
  40. +1 −1 activerecord/lib/rails/generators/active_record/model/model_generator.rb
  41. +1 −1 activerecord/test/cases/autosave_association_test.rb
  42. +2 −2 activerecord/test/cases/callbacks_test.rb
  43. +1 −1 activerecord/test/cases/fixtures_test.rb
  44. +1 −1 activerecord/test/cases/locking_test.rb
  45. +1 −1 activerecord/test/cases/relation/mutation_test.rb
  46. +1 −1 activerecord/test/cases/timestamp_test.rb
  47. +1 −1 activerecord/test/models/customer.rb
  48. +1 −1 activesupport/lib/active_support/core_ext/array/grouping.rb
  49. +1 −1 activesupport/lib/active_support/core_ext/date/calculations.rb
  50. +2 −2 activesupport/lib/active_support/testing/isolation.rb
  51. +1 −1 activesupport/lib/active_support/xml_mini/libxmlsax.rb
  52. +1 −1 activesupport/lib/active_support/xml_mini/nokogirisax.rb
  53. +1 −1 railties/lib/rails/application/configuration.rb
  54. +2 −2 railties/lib/rails/engine.rb
  55. +1 −1 railties/lib/rails/generators/actions.rb
  56. +1 −1 railties/lib/rails/generators/base.rb
  57. +1 −1 railties/lib/rails/generators/erb/mailer/mailer_generator.rb
  58. +1 −1 railties/lib/rails/generators/migration.rb
  59. +1 −1 railties/lib/rails/generators/named_base.rb
  60. +1 −1 railties/lib/rails/test_help.rb
@@ -31,7 +31,7 @@ class Engine < Rails::Engine # :nodoc:
self.cable = Rails.application.config_for(config_path).with_indifferent_access
end
- previous_connection_class = self.connection_class
+ previous_connection_class = connection_class
self.connection_class = -> { "ApplicationCable::Connection".safe_constantize || previous_connection_class.call }
options.each { |k, v| send("#{k}=", v) }
@@ -13,7 +13,7 @@ def create_channel_file
template "channel.rb", File.join("app/channels", class_path, "#{file_name}_channel.rb")
if options[:assets]
- if self.behavior == :invoke
+ if behavior == :invoke
template "assets/cable.js", "app/assets/javascripts/cable.js"
end
@@ -30,7 +30,7 @@ def file_name
# FIXME: Change these files to symlinks once RubyGems 2.5.0 is required.
def generate_application_cable_files
- return if self.behavior != :invoke
+ return if behavior != :invoke
files = [
"application_cable/channel.rb",
@@ -59,7 +59,7 @@ def add_delivery_method(symbol, klass, default_options = {})
end
def wrap_delivery_behavior(mail, method = nil, options = nil) # :nodoc:
- method ||= self.delivery_method
+ method ||= delivery_method
mail.delivery_handler = self
case method
@@ -63,7 +63,7 @@ def all
# interceptors will be informed so that they can transform the message
# as they would if the mail was actually being delivered.
def call(email)
- preview = self.new
+ preview = new
message = preview.public_send(email)
inform_preview_interceptors(message)
message
@@ -57,7 +57,7 @@ def tests(mailer)
end
def mailer_class
- if mailer = self._mailer_class
+ if mailer = _mailer_class
mailer
else
tests determine_default_mailer(name)
@@ -11,7 +11,7 @@ def create_mailer_file
template "mailer.rb", File.join("app/mailers", class_path, "#{file_name}_mailer.rb")
in_root do
- if self.behavior == :invoke && !File.exist?(application_mailer_file_name)
+ if behavior == :invoke && !File.exist?(application_mailer_file_name)
template "application_mailer.rb", application_mailer_file_name
end
end
@@ -37,7 +37,7 @@ def head(status, options = {})
if include_content?(response_code)
self.content_type = content_type || (Mime[formats.first] if formats)
- self.response.charset = false
+ response.charset = false
end
true
@@ -114,7 +114,7 @@ def _process_options(options)
self.status = status if status
self.content_type = content_type if content_type
- self.headers["Location"] = url_for(location) if location
+ headers["Location"] = url_for(location) if location
super
end
@@ -150,7 +150,7 @@ def initialize(parameters = {})
# permitted flag.
def ==(other)
if other.respond_to?(:permitted?)
- self.permitted? == other.permitted? && self.parameters == other.parameters
+ permitted? == other.permitted? && parameters == other.parameters
else
@parameters == other
end
@@ -354,7 +354,7 @@ def controller_class=(new_class)
end
def controller_class
- if current_controller_class = self._controller_class
+ if current_controller_class = _controller_class
current_controller_class
else
self.controller_class = determine_default_controller_class(name)
@@ -269,8 +269,8 @@ def test_post
test "response cookies are added to the cookie jar for the next request" do
with_test_route_set do
- self.cookies["cookie_1"] = "sugar"
- self.cookies["cookie_2"] = "oatmeal"
+ cookies["cookie_1"] = "sugar"
+ cookies["cookie_2"] = "oatmeal"
get "/cookie_monster"
assert_equal "cookie_1=; path=/\ncookie_3=chocolate; path=/", headers["Set-Cookie"]
assert_equal({ "cookie_1" => "", "cookie_2" => "oatmeal", "cookie_3" => "chocolate" }, cookies.to_hash)
@@ -26,7 +26,7 @@ def test_nested_optional
action: :index
}
}.url_helpers
- self.default_url_options[:host] = "example.com"
+ default_url_options[:host] = "example.com"
}
path = klass.new.fun_path(controller: :articles,
@@ -1603,7 +1603,7 @@ def test_redirect_with_port
get "account/login", to: redirect("/login")
end
- previous_host, self.host = self.host, "www.example.com:3000"
+ previous_host, self.host = host, "www.example.com:3000"
get "/account/login"
verify_redirect "http://www.example.com:3000/login"
@@ -16,7 +16,7 @@ def render
class << self
def select_type
- @select_type ||= self.name.split("::").last.sub("Select", "").downcase
+ @select_type ||= name.split("::").last.sub("Select", "").downcase
end
end
@@ -17,7 +17,7 @@ def render
class << self
def field_type
- @field_type ||= self.name.split("::").last.sub("Field", "").downcase
+ @field_type ||= name.split("::").last.sub("Field", "").downcase
end
end
@@ -319,7 +319,7 @@ def _write_layout_method # :nodoc:
name_clause
end
- self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
def _layout(formats)
if _conditional_layout?
#{layout_definition}
@@ -206,8 +206,8 @@ def view
view = @controller.view_context
view.singleton_class.include(_helpers)
view.extend(Locals)
- view.rendered_views = self.rendered_views
- view.output_buffer = self.output_buffer
+ view.rendered_views = rendered_views
+ view.output_buffer = output_buffer
view
end
end
@@ -5,7 +5,7 @@ module ViewPaths
included do
class_attribute :_view_paths
self._view_paths = ActionView::PathSet.new
- self._view_paths.freeze
+ _view_paths.freeze
end
delegate :template_exists?, :any_templates?, :view_paths, :formats, :formats=,
@@ -61,7 +61,7 @@ def self.use_relative_model_naming?
class PolymorphicRoutesTest < ActionController::TestCase
include SharedTestRoutes.url_helpers
- self.default_url_options[:host] = "example.com"
+ default_url_options[:host] = "example.com"
def setup
@project = Project.new
@@ -19,7 +19,7 @@ def create_job_file
template "job.rb", File.join("app/jobs", class_path, "#{file_name}_job.rb")
in_root do
- if self.behavior == :invoke && !File.exist?(application_job_file_name)
+ if behavior == :invoke && !File.exist?(application_job_file_name)
template "application_job.rb", application_job_file_name
end
end
@@ -56,7 +56,7 @@ class QueueNamingTest < ActiveSupport::TestCase
original_queue_name = HelloJob.queue_name
begin
- HelloJob.queue_as { self.arguments.first == "1" ? :one : :two }
+ HelloJob.queue_as { arguments.first == "1" ? :one : :two }
assert_equal "one", HelloJob.new("1").queue_name
assert_equal "two", HelloJob.new("3").queue_name
ensure
@@ -32,7 +32,7 @@ class QueuePriorityTest < ActiveSupport::TestCase
original_priority = HelloJob.priority
begin
- HelloJob.queue_with_priority { self.arguments.first == "1" ? 99 : 11 }
+ HelloJob.queue_with_priority { arguments.first == "1" ? 99 : 11 }
assert_equal 99, HelloJob.new("1").priority
assert_equal 11, HelloJob.new("3").priority
ensure
@@ -4,7 +4,7 @@ module Sneakers
module Worker
module ClassMethods
def enqueue(msg)
- worker = self.new(nil, nil, {})
+ worker = new(nil, nil, {})
worker.work(*msg)
end
end
@@ -234,7 +234,7 @@ def self.extended(base) #:nodoc:
# Person.model_name.plural # => "people"
def model_name
@_model_name ||= begin
- namespace = self.parents.detect do |n|
+ namespace = parents.detect do |n|
n.respond_to?(:use_relative_model_naming?) && n.use_relative_model_naming?
end
ActiveModel::Name.new(self, namespace)
@@ -44,7 +44,7 @@ def human_attribute_name(attribute, options = {})
parts = attribute.to_s.split(".")
attribute = parts.pop
namespace = parts.join("/") unless parts.empty?
- attributes_scope = "#{self.i18n_scope}.attributes"
+ attributes_scope = "#{i18n_scope}.attributes"
if namespace
defaults = lookup_ancestors.map do |klass|
@@ -1857,7 +1857,7 @@ def destroy_associations
end
has_many name, scope, hm_options, &extension
- self._reflections[name.to_s].parent_reflection = habtm_reflection
+ _reflections[name.to_s].parent_reflection = habtm_reflection
end
end
end
@@ -100,7 +100,7 @@ def delete_count(method, scope)
end
def delete_or_nullify_all_records(method)
- count = delete_count(method, self.scope)
+ count = delete_count(method, scope)
update_counter(-count)
end
@@ -9,7 +9,7 @@ module PrimaryKey
# available.
def to_key
sync_with_transaction_state
- key = self.id
+ key = id
[key] if key
end
@@ -328,9 +328,9 @@ def validate_collection_association(reflection)
def association_valid?(reflection, record, index = nil)
return true if record.destroyed? || (reflection.options[:autosave] && record.marked_for_destruction?)
- validation_context = self.validation_context unless [:create, :update].include?(self.validation_context)
+ context = validation_context unless [:create, :update].include?(validation_context)
- unless valid = record.valid?(validation_context)
+ unless valid = record.valid?(context)
if reflection.options[:autosave]
indexed_attribute = !index.nil? && (reflection.options[:index_errors] || ActiveRecord::Base.index_nested_attribute_errors)
@@ -450,7 +450,7 @@ def ==(comparison_object)
# [ Person.find(1), Person.find(2), Person.find(3) ] & [ Person.find(1), Person.find(4) ] # => [ Person.find(1) ]
def hash
if id
- self.class.hash ^ self.id.hash
+ self.class.hash ^ id.hash
else
super
end
@@ -472,7 +472,7 @@ def frozen?
# Allows sort on objects
def <=>(other_object)
if other_object.is_a?(self.class)
- self.to_key <=> other_object.to_key
+ to_key <=> other_object.to_key
else
super
end
@@ -885,7 +885,7 @@ module ClassMethods
#
# The keys must be the fixture names, that coincide with the short paths to the fixture files.
def set_fixture_class(class_names = {})
- self.fixture_class_names = self.fixture_class_names.merge(class_names.stringify_keys)
+ self.fixture_class_names = fixture_class_names.merge(class_names.stringify_keys)
end
def fixtures(*fixture_set_names)
@@ -393,7 +393,7 @@ def _destroy
# update_only is true, and a <tt>:_destroy</tt> key set to a truthy value,
# then the existing record will be marked for destruction.
def assign_nested_attributes_for_one_to_one_association(association_name, attributes)
- options = self.nested_attributes_options[association_name]
+ options = nested_attributes_options[association_name]
if attributes.respond_to?(:permitted?)
attributes = attributes.to_h
end
@@ -452,7 +452,7 @@ def assign_nested_attributes_for_one_to_one_association(association_name, attrib
# { id: '2', _destroy: true }
# ])
def assign_nested_attributes_for_collection_association(association_name, attributes_collection)
- options = self.nested_attributes_options[association_name]
+ options = nested_attributes_options[association_name]
if attributes_collection.respond_to?(:permitted?)
attributes_collection = attributes_collection.to_h
end
@@ -562,7 +562,7 @@ def reject_new_record?(association_name, attributes)
def call_reject_if(association_name, attributes)
return false if will_be_destroyed?(association_name, attributes)
- case callback = self.nested_attributes_options[association_name][:reject_if]
+ case callback = nested_attributes_options[association_name][:reject_if]
when Symbol
method(callback).arity == 0 ? send(callback) : send(callback, attributes)
when Proc
@@ -87,8 +87,8 @@ class Railtie < Rails::Railtie # :nodoc:
if File.file?(filename)
cache = YAML.load(File.read(filename))
if cache.version == ActiveRecord::Migrator.current_version
- self.connection.schema_cache = cache
- self.connection_pool.schema_cache = cache.dup
+ connection.schema_cache = cache
+ connection_pool.schema_cache = cache.dup
else
warn "Ignoring db/schema_cache.yml because it has expired. The current schema version is #{ActiveRecord::Migrator.current_version}, but the one in the cache is #{cache.version}."
end
@@ -11,7 +11,7 @@ module ClassMethods
# Attributes listed as readonly will be used to create a new record but update operations will
# ignore these fields.
def attr_readonly(*attributes)
- self._attr_readonly = Set.new(attributes.map(&:to_s)) + (self._attr_readonly || [])
+ self._attr_readonly = Set.new(attributes.map(&:to_s)) + (_attr_readonly || [])
end
# Returns an array of all the attributes that have been specified as readonly.
@@ -260,7 +260,7 @@ def batch_order
end
def act_on_ignored_order(error_on_ignore)
- raise_error = (error_on_ignore.nil? ? self.klass.error_on_ignored_order : error_on_ignore)
+ raise_error = (error_on_ignore.nil? ? klass.error_on_ignored_order : error_on_ignore)
if raise_error
raise ArgumentError.new(ORDER_IGNORE_MESSAGE)
@@ -193,7 +193,7 @@ def perform_calculation(operation, column_name)
# If #count is used with #distinct (i.e. `relation.distinct.count`) it is
# considered distinct.
- distinct = self.distinct_value
+ distinct = distinct_value
if operation == "count"
column_name ||= select_for_count
@@ -656,7 +656,7 @@ def or!(other) # :nodoc:
end
self.where_clause = self.where_clause.or(other.where_clause)
- self.having_clause = self.having_clause.or(other.having_clause)
+ self.having_clause = having_clause.or(other.having_clause)
self
end
@@ -46,7 +46,7 @@ def sanitize_sql_for_conditions(condition) # :doc:
#
# sanitize_sql_for_assignment("name=NULL and group_id='4'")
# # => "name=NULL and group_id='4'"
- def sanitize_sql_for_assignment(assignments, default_table_name = self.table_name) # :doc:
+ def sanitize_sql_for_assignment(assignments, default_table_name = table_name) # :doc:
case assignments
when Array; sanitize_sql_array(assignments)
when Hash; sanitize_sql_hash_for_assignment(assignments, default_table_name)
@@ -27,7 +27,7 @@ def has_secure_token(attribute = :token)
# Load securerandom only when has_secure_token is used.
require "active_support/core_ext/securerandom"
define_method("regenerate_#{attribute}") { update! attribute => self.class.generate_unique_secure_token }
- before_create { self.send("#{attribute}=", self.class.generate_unique_secure_token) unless self.send("#{attribute}?") }
+ before_create { send("#{attribute}=", self.class.generate_unique_secure_token) unless send("#{attribute}?") }
end
def generate_unique_secure_token
Oops, something went wrong.

0 comments on commit 5473e39

Please sign in to comment.