Yamal Khaled Soueidan wrote: > Hello everyone, > > I have been discussing the difference between methods and functions with a > friend, but we couldn't agree on what method and function is? > > I would be very glad if people can join us. > At the moment we have 2 definition for the names. > > 1. first, both names are the same, you can use whatever you want, they > refer > to the same thing. > > 2. functions is used outside class, so you can call them direct, they are > global functions, whereas methods are inside classes, and you cannot call > them direct without creating object of that class which have the methods. > > What do you agree on, or what do you have in mind, when you hear > function or > method? I think of them like this: - A method is a message to which an object responds. - A function is a mapping from a set of input arguments to an output value (possibly with side-effects). By this definition, it is possible for an (object,message) pair to be viewed as a function. In a sense, your point 1 above is closest to the truth in Ruby - it's not possible to define a function that's not implemented as a method on an object. -- Alex