Does pure OO matter?
Ruby is a pure OO language, in other words, it has no functions. Even if a "def" statement outside of a class definition looks and behaves like a function, it is actually a private methods of class Object.
You may ask, is this just an implementation details? Well, most of the time it doesn't matter, people can ignore the difference and use those methods as functions -- no problem at all. It only matters when you use introspect(reflection). For example, the following code:
will print:
Reference:
[0] Ruby FAQ: How Does Ruby Compare With Python?
You may ask, is this just an implementation details? Well, most of the time it doesn't matter, people can ignore the difference and use those methods as functions -- no problem at all. It only matters when you use introspect(reflection). For example, the following code:
def my_global_function
end
puts Object.private_methods
will print:
...
my_global_function
exit
putc
system
...
Reference:
[0] Ruby FAQ: How Does Ruby Compare With Python?
0 Comments:
Post a Comment
<< Home