From: John Joyce Date: 2007-03-28T21:56:52+09:00 Subject: Re: general question (different between methods and functions)? The answer does depend on the language in question! The difference is small and (arguably) unimportant in Ruby. In C++ or Objective-C the difference and distinction is more clear and more important. Some people would argue the semantic difference between a function and a method, but in most cases, in most languages they're pretty much the same. The main difference is that a method is "part" of an object. It must understand (respond to) or "have" the method in its definition. (or inherit the method from an ancestor class) A function in the strictest sense is a bit of code that is defined and named and can be called and run by that name. It may take arguments (parameters) and / or return a value of some sort. In Ruby almost everything is an object... Objective-C, has a similar concept of methods and messages to Ruby, but also has C as it's strict subset, it is a good place to find out about the differences and similarities. On Mar 28, 2007, at 9:34 PM, Yamal Khaled Soueidan wrote: > Thats what I meant, functions is used without the object, and are > called > direct, whereas the methods is used with the object. > > puts "this is a function" > > File.puts "this is object.method" > > Is this how everyone see it or do many people have different > opinion on this > subject? > > On 3/28/07, James Edward Gray II wrote: >> >> On Mar 28, 2007, at 3:42 AM, SonOfLilit wrote: >> >> > Methods are associated with a receiver object. >> > >> > Functions are not. >> > >> > The only things you can call functions in Ruby are lambdas, blocks, >> > ... Even then it's not clear whether they are methods or functions. >> > >> > Everything else is methods. >> >> The above is all true, but we do sometimes refer to calling methods >> in a "function-style" in Ruby. That's when you call a method without >> an explicit receiver. For example: >> >> puts "Hello world!" # function-style >> file.puts "Hello world!" # normal method call >> >> Everything is still a method, this is just a name we use for the call >> style. >> >> I only bring it up because it is sometimes referred to in the >> documentation for things like private scope and module_function. >> >> James Edward Gray II >> >> >>