You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This paper compare Ruby and Java in some features of two language. I take a note about Object Orientation part:
As defines, Object Orientation of a language is determined based on the following qualities
Encapsulation/Information Hiding
Inheritance
Polymorphism/Dynamic Binding
All pre-defined types are Objects
All operations performed by sending messages to Objects
All user-defined types are Objects
All the above properties are satisfied by Ruby. But Java has eight “basic” types that are not objects. On the other hand, everything in Ruby is an Object. Java also fails to meet quality 5 by implementing basic arithmetic as built-in operators, rather than messages to objects. So Java cannot be classified as a Pure Object Oriented Language. But except the way eight basic types are handled, everything else in Java in an object.
I emphasize on Property 5 "sending messages to Objects" , this is useful feature in Ruby, help programmer write code in elegant way.
In Ruby, the send method is used to pass message to Object. send() accepts the name of the method to be invoked as it’s first argument, either as a string or symbol. This is useful when the method to be called is not known in advance, and is to be determined at runtime.
With send() method, instead of write code in more verbose way
defmy_method(array_of_args,action)ifaction == :summy_math.sum(array_of_args)elsifaction == :averagemy_math.average(array_of_args)# ... can have a lot of if-else statement endend
We can write(its first argument which corresponds to the method name):
(Move from old blog). Recently, I have read the CS paper compare Ruby and Java.
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.127.2138&rep=rep1&type=pdf
This paper compare Ruby and Java in some features of two language. I take a note about Object Orientation part:
As defines, Object Orientation of a language is determined based on the following qualities
All the above properties are satisfied by Ruby. But Java has eight “basic” types that are not objects. On the other hand, everything in Ruby is an Object. Java also fails to meet quality 5 by implementing basic arithmetic as built-in operators, rather than messages to objects. So Java cannot be classified as a Pure Object Oriented Language. But except the way eight basic types are handled, everything else in Java in an object.
I emphasize on Property 5 "sending messages to Objects" , this is useful feature in Ruby, help programmer write code in elegant way.
In Ruby, the send method is used to pass message to Object. send() accepts the name of the method to be invoked as it’s first argument, either as a string or symbol. This is useful when the method to be called is not known in advance, and is to be determined at runtime.
With send() method, instead of write code in more verbose way
We can write(its first argument which corresponds to the method name):
For example, this code implement "reverse polish notation", use send() to write better code:
The text was updated successfully, but these errors were encountered: