Remove unnecessary "send" from initializers

Description

# lib/gitlab/git/tree.rb
def initialize(options)
  %w(id root_id name path flat_path type mode commit_id).each do |key|
    self.send("#{key}=", options[key.to_sym]) # rubocop:disable GitlabSecurity/PublicSend
  end
end

# lib/gitlab/git/blob.rb
def initialize(options)
  %w(id name path size data mode commit_id binary).each do |key|
    self.__send__("#{key}=", options[key.to_sym]) # rubocop:disable GitlabSecurity/PublicSend
  end

  @loaded_all_data = false
  # Retain the actual size before it is encoded
  @loaded_size = @data.bytesize if @data
end

Using "send" here to save a few lines of boilerplate code creates code that is harder to read. Every reader of this code has to pause for a few second to understand what is going on here.

Proposal

Replace "smart code" with "boring code".

def initialize(options)
  self.id = options[:id]
  self.root_id = options[:root_id]
  self.name = options[:name]
  self.path = options[:path]
  self.flat_path = options[:flat_path]
  self.type = options[:type]
  self.mode = options[:mode]
  self.commit_id = options[:commit_id]
end
Assignee Loading
Time tracking Loading