Tuesday, March 13, 2012

Capitalized methods names

You can define methods with capitalized names:


def Foo
  puts 'foo'

def Bar x
  puts x

At call time, to avoid Ruby to interpret them as constants, you must make clear that you are using them as functions, by using parenthesis or parameters:

Foo()      #=> 'foo'
Bar 3      #=> 3
Foo        #=> Error: not initialized constant

Sequel uses this feature to define methods named String, Integer, etc. for creating/altering tables.

No comments:

Post a Comment