Delete duplicate string characters in a array

I didn’t notice tabs and spaces were mixed! Mixing is no good idea as there is no universally defined tabstop. Some systems/editors use 2, some 4 and some 8. Sticking to spaces only is the safest and most editors have a setting for this.

Regarding variable naming using abbreviation doesn’t help separate to them from methods as methods could also be named using abbreviation. Also, there are no methods named model, selection or material in the namespace used, so there is no risk of a mix-up.

Here’s my edited code with the following changes:

  • indentation
  • using full words instead of abbreviation (where i understand what it is supposed to mean),
  • using placeholder variable names var1, var2 etc where I don’t understand what is is supposed to mean,
  • using placeholder variable and method names for everything in French and
  • using placeholder operation name.
def french1(entities)
  model = Sketchup.active_model
  materials = model.materials
  model.start_operation('Operator Name', true)
  entities.grep(Sketchup::ComponentInstance).each do |entity|
    ["Exploser"].each do |french2|
      if entity.definition.name =~ /#{french2}/
        if entity.material.name.include?("PN")
          var1 = []
          var1 << "#{entity.material.name}-#{entity.definition.name}"
          var2 = var1.uniq
          puts var2
          path = File.join(
            Sketchup.find_support_file('plugins'),
            "TNT_ClickCuisine2/Materials/FACADES/"
          )
          for var3 in var2
            var2.each do |var4|
              mattex = "4-#{var4.split("-")[0]}.jpg"
              var5 = materials.add(var4)
              var5 = materials[var3]
              var5.texture = path + mattex
              entity.material = var5
            end
          end
        end
      end
    end
    french1(entity.definition.entities)
  end
  model.commit_operation
end

model = Sketchup.active_model
selection = model.selection
instances = selection.grep(Sketchup::ComponentInstance)
french1(instances)

You can change all the placeholder names to meaningful names that tell what a method does and what a variable represents. I just also noticed that mattex probably should be changed to file_name as it seems to represent a file name (not a material or texture or whatever mattex even refers to).

It is very hard for us here in the forum to understand what the code is even supposed to do when we don’t understand what variables are supposed to represent. It will also be equally hard for you to understand these names if you need to make any changes to the code in a few years from now when you no longer have it fresh in memory.