Self.reset vs. reset


I’ve noticed in the various sample tools that I’ve been studying that in some of the methods reset is called out instead of self.reset, is there a particular reason for this?


This is Ruby 101! In Ruby there is always a current “receiver “ object. Any methods invoked without explicit qualification such as reset are handled by this object. If you pretend the method name with a variable name and a dot, as foo.reset, the method is processed by the object referenced by the variable. The variable “self” always refers to the current receiver. So the two forms are in this case equivalent. Choice of one vs the other is just style.

Edit: of course that was supposed to be “prepend “ but autocorrect fixed it for me!


Did not know that, unfortunately I am not a Ruby programmer, I only know enough to be dangerous and somehow cobble together a few plugins.


Self is often redundant when making method calls. The exceptions are setter methods which need to be explicitly called with not to just assign local variable and self.class to get a reference to the class, as class itself is a keyword.

Rubocop helps with this, among many, many other things. Sketchup-rubocop also helps a lot for extension development, e.g. by warning for use of slow methods in the API.