Ruby Summary

  1. In Ruby, we rely less on the type (or class) of an object and more on its capabilities. Hence, Duck Typing means an object type is defined by what it can do, not by what it is.
  2. Duck Typing refers to the tendency of Ruby to be less concerned with the class of an object and more concerned with what methods can be called on it and what operations can be performed on it.
  3. In Ruby, we would use respond_to? or might simply pass an object to a method and know that an exception will be raised if it is used inappropriately.
  4. Syntactic sugar refer to special rules that let you write your code in a way that doesn't correspond to the normal rules but that is easier to remember and looks better.
  5. Ruby allows you to define methods that end with an equal sign (=)
  6. Mutable objects are objects whose state can change. Immutable objects are objects whose state never changes after creation.
  7. Mutability is a property of an instance, not of an entire class. Any instance can become immutable by calling freeze.
  8. The freeze method in class Object prevents you from changing an object, effectively turning an object into a constant. After we freeze an object, an attempt to modify it results in TypeError.
  9. freeze operates on an object reference, not on a variable. This means that any operation resulting in a new object will work.
  10. A method frozen? tells you whether an object is frozen or not.

Note: The Ruby Logo is Copyright (c) 2006, Yukihiro Matsumoto. I have made extensive references to information, related to Ruby, available in the public domain (wikis and the blogs, articles of various Ruby Gurus), my acknowledgment and thanks to all of them. Much of the material on rubylearning.github.io and in the course at rubylearning.org is drawn primarily from the Programming Ruby book, available from The Pragmatic Bookshelf.