rubycode-snippetsinformation-hidingmethod-hidingname-hiding

Replace class and variables names in code snippet


I would like to insert some gist-s of my code in CV. In order not to give idea what this code is about I want to replace all classes, methods and variables names with some random strings automatically (using some script or online creator?), so that I can show "how I write" but I don't show real functionality.

class User
  def initialize(email)
    @email = email
    @is_admin = false
  end

  def give_admin
    self.update(is_admin: true)
  end

  [...]
end

I would like to change into:

class Class1
  def method_1(var1)
    @var1 = var1
    @var2 = false
  end

  def method_2
    self.update(var2: true)
  end

  [...]
end

or maybe someone know better way to show somebody else "how does my code looks like but without showing him functionality"?

Thanks in advance


Solution

  • To answer your question:

    You might want to use a Ruby source code uglifier/minifier (for example: ruby2ruby).


    BUT (and that's all caps "but")

    Don't do it! When someone is looking at your code, s/he does not want to see some random ruby code. The name of the class, the method names, etc. are very important in evaluating code. Who cares about the class names you have written in the past? Most probably, there are gazillion of other developers that have named their classes using exactly the same names as your showcase classes. So, post probably no one would care. Just give the exact classes you wrote, remove some private things that they may contain and share them.

    If you really don't want to share some classes that you are really proud of, then write another (new) classes and showcase all your skills in there!

    PS. If someone wants to evaluate your code without knowing the class and method names, then grab your code and run like hell! You probably better off without them! :) You will not learn much from that team lead. Or, if you do, you will learn the wrong things.