How is Ruby fully Object Oriented?
oop, ruby
Solution
- User defined global functions (top-level functions) are instance methods of `Object` (even though the class of `self` is not `Object`).
- Top-level methods are always private.
Problem
So, I'm curious as to how Ruby is a fully object oriented language. I stumble over one problem that isn't really clear to me. If I define a function as follows ``` def foo(text) print text end ``` and I define the function outside of a class, how is this function an object? I realize that I can call ``` foo.class ``` And I get NilClass. Does this mean that foo is an instance of NilClass? And if it is, what does it mean exactly when I call ``` foo "hello world" ``` If foo is an object, what method am I calling when I make the statement as above. Also, if it an object, does that mean I can modify it and add another method to it (say bar) where I could possibly make the following statment: ``` foo.bar(some variables) ``` Sorry, I'm just a little confused on this point. Any clarification is very much appreciated! Thanks!