It’s a well-known fact that Ruby language has no requirements for parenthesis, but we also could have variables and methods with identical names:

something

# => NameError (undefined local variable or method `something` ... def something; :method; end

something() # => :method

something # => :method something = :variable

something() # => :method

something # => :variable

So, in the first place, we are looking for a variable and just then for a method with the same name. It’s more explicit when the method is invoked with parenthesis, but there is no reason for it:

user.update(first_name: 'John')

What is user in the above example? Yes, it could be variable or method but in both cases, we expect some value, no matter how it is delivered. In some cases, during refactoring, we simply could just replace a variable with the method or replace method with inline variable without additional changes.

One more interesting case is the situation with constant variables which are used for Class instances and regular constants LIKE_THIS :

ONE = 1

def ONE

1.0

end ONE # => 1

ONE() # => 1.0 # but def TWO

2.0

end TWO # => NameError (uninitialized constant TWO)

TWO() # => 2.0

As you can see there is a difference between regular variable and constant variables, there is no lookup by methods, so even if you have a method with the same name as constant it will not be invoked until you explicitly use parenthesis or pass arguments to it. While we could have method names similar to constant names it looks strange, but situation with constants used for Class instances are different:

def Person(first_name, last_name)

Person.new(first_name, last_name)

end class Person

def initialize(first_name, last_name)

@first_name = first_name

@last_name = last_name

end

end Person("Ricky", "Martin") # => #<Person:....>

In the above example, we use a method with the same name as our Class instance variable name to perform the creation of new instances which may have no much sense, but there are more useful examples — in Ruby, we have such methods like Array() which tries to invoke to_ary or to_a on argument passed to it, so it could be used for conversion. Also, we could get some example from dry-rb, where we have such methods for generating new Class instances: