First, the introduction
Ruby on Rails is just a factor in making Ruby great, as EJB is just one part of the Java Enterprise platform. This article will bring you together as a Java developer, leveraging only the functionality that Ruby itself can achieve.
Let me first clarify some questions. First, this is not an article about Ruby on Rails. If you want to learn about rails, new articles and blogs are published every week to celebrate this exciting framework and its various features. Second, this article is not a warning that the Java platform is about to crash when there are some better languages, tools, and frameworks (such as Ruby on Rails). Therefore, this article has little to do with the recent topic about Ruby.
Don't get me wrong--in my opinion, rails is pretty neat! It is so amazingly powerful that it obviously affects many aspects of web development. My only opinion is that there are more things about ruby than rails, especially when viewed from a Java developer's perspective. The specialty of Rails is web development, but I find myself not using this technique very often when building websites. Most of the sites I build are mainly using struts,tapestry or some other technology. When I take advantage of Ruby, I use it only as part of development practice. So, in this article, I'll discuss how to develop with Ruby if you're primarily a Java developer.
Second, the initial feeling
Ruby's syntax differs significantly from the Java language. First, Ruby has no parentheses or semicolons, and its type is entirely optional. Some people may say that Ruby's syntax is quite refined, and one of its purposes is to write concise code with short commands.
You can appreciate this by comparing the implementation of a relatively functional class, and in this article we first define it in the Java language and then implement it in Ruby. In this article I first use two classes: Word and definition. In the simple class diagram in Figure 1, you can see that two classes share some relationships:
A word has a synonym (also known as a Word instance) collection.
A word can also have a definition collection.
A definition has an aggregation association to Word (aggregation association).