DEV Community

Ty
Ty

Posted on

Experience with Ruby

I have never heard of ruby until late 2019. As a community college student I have been focused on Java and C++. Hearing about ruby as a great introduction language got me curious. Joining my bootcamp, the first module we learned were the basics of ruby. While working on my assignments with ruby, there were many similarities with java and C++. However Ruby has its own unique twist to them, more so, simplified.

Example making a method

For Ruby it is much simpler making a method compared to Java

def methodname

end

You only have to type 3 words. Defining the method name and ending that code block.

Such as Java, it'll take you a little longer to write a method. Since you would have to call the datatype of the method and wether the method is public or private.

public static string methodname {

}

Even then it's the small things that makes you appreciate Ruby. Such as not using { } for if statements or loops. Even having more built in methods was a huge plus.

Example, need to know the min-max of an array? There's a method for that literally called 'min-max'! Need to remove duplicates in an array? Theres another easy method for that called '.uniq'.

Not only that, you do not need to set a type for your variable. No longer needing to say 'int var' or 'string var', you can just type 'var = nil'
and var could be any datatype. It could hold a float, double, integer, string, and more without needing to specify.

Whats even crazy is that you can use macros in order to write most of your setters and getters. Instead of typing out every method for your getters and setters. You can use "attr_accessor, attr_writer, and attr_reader" for your setters and getters. No more writing set and get. Everything can be stored in one whole line!

Which is why I say Ruby is such a good introduction language. It super simplified which in terms helps remove common errors like using the wrong datatype for a variable. ("Using integer when you need it as a double")

Top comments (0)