The convenience of Ruby 2.1 def returning a symbol instead of nil


Prior to 2.1, if you defined a method, you received nil as a return value:

irb(main):001:0> def fun
irb(main):002:1> end
=> nil

With 2.1, the method definition returns a symbol for the method name:

irb(main):001:0> def fun
irb(main):002:1> end
=> :fun

One impact of this is that the following pattern for declaring a single private method

  def fun
  end
  private :fun

can become:

  private def fun
  end

Now to decide if I like how that looks.


%d bloggers like this: