First class functions

When describing a programming language, what does the term ‘first class functions’ mean? Essentially it means that you can treat the function the same way that you would treat a variable. Jörg W Mittag says that first class functions should adhere to 4 rules:

  • They may be passed by name as variables
  • They may be passed as arguments to procedures
  • They may be returned as results from procedures
  • They may be included in data structures

By this definition, Ruby methods are not first-class citizens. Ruby methods cannot be passed by name, unlike JavaScript functions. However, Ruby Procs are first class citizens.

Further reading