What's new (to you) in Ruby?

For the longest time I thought the way to describe a method on an object/class/method was simply Class#method. After some one pointed out something to me on my 101 Ruby Code Factoid blogpost I’ve since learned that the pound-method is for methods that end up on multiple instances.

For example

module A
  def a
  end
end

class B
  def b
  end
end

Both of these would be documented as A#a and B#b because the method can be repopulated on to many instances of the objects. But for methods written specifically on the class module definition it get’s written differently.

module C
  def self.c
  end
end

class D
  def self.d
  end
end

These would be documented as C.c and D.d

Now You Know!

3 Likes