Today I Learnt

Endless Method Definitions in Ruby

After nearly 20 years of writing Ruby, I still love discovering new features. Even when they aren’t new!

Perfect for interface definitions …

module Foo
  def name = raise NotImplementedError
  def description = raise NotImplementedError
  def parameters = {}
  def call(**kwargs) = raise NotImplementedError
end

class Bar
  include Foo
end

… or functional one-liners …

def self_power_less_self(int) = int ** int - int

self_power_less_self 3
# => 24