Based on the Java background, I'm a little concerned about Ruby completely blasé about its method parameters. While in Java I could guarantee that the parameter x is the type necessary for the method to work correctly, in Ruby I have no way to guarantee that x is an integer, string, or something else for that matter.
Example: if I wanted to write the absolute_value method in Java, the header would look like
public static int absoluteValue(int x)
In Ruby, it will be something like
def self.absolute_value(x)
In this example, in Java code, I can be absolutely sure that the parameter passed is not "Happy Birthday!" but in the Ruby code I don't know that. How to prevent this situation in Ruby so that the code doesn't crash into Runtime?
source
share