Leap Across To Ruby - 1 - Shantanu's Blog
This post is for experienced programmers who are familiar with object-oriented programming. Let’s say you are migrating from Java to Ruby. After five years in Java, you know what you want from a programming language. To start with, you just need to know how to declare variables, functions, classes and class variables. Also, you need to know how "if" and "for" are implemented.
Here I will present a piece of code with liberal annotations to make things clear.
Every language has its share of strange stuff. Probably their creators fall for the natural human tendency of achieving notoriety by doing things differently.Take the example of the "case" statement. One form of it, wherein you do not return a value, looks pretty normal. But the other one, the one in red, surely stands out.
Iteration has an uncommon syntax. This is besides the "for x in list" style.
There is a concept called "implicit return" in Ruby. If you do not add a return statement explicitly to a function, the output of the last line will be returned. In the following examples, both the syntaxes are correct. Little strange, yet stylish.
June 7th, 2022