Ruby: A programmer’s best friend
Sunil Sharma
Turning frowns into clickable smiles! ?? Enterprise UX Analyst on a mission to make software so user-friendly, even your coffee machine will ask for feedback.??
Multi-paradigm: functional, imperative, object-oriented, reflective
In this article, I have shared basic information about Ruby programming language for those who are going to kick-start with.
The popularity of Ruby is getting gradually higher, even if it looks at the share rate of the programming language, it also enters the ranking top. Ruby is one of the most popular languages among tech start-ups. Many tech unicorns have been built on Ruby, including Airbnb, Twitch, GitHub, and Twitter. Its popularity perhaps dependent on Ruby on Rails, a full-stack web application framework that runs Ruby.
Ruby is simple in appearance, but is very complex inside, just like our human body. -From the Official Article
Overview
Ruby is a dynamic, open-source, object-oriented and reflective programming language. Ruby is similar to Perl and Smalltalk programming language. It runs on all types of platforms like Windows, Mac OS and all versions of UNIX. Ruby is considered to follow the principle of POLA (principle of least astonishment). It means that the language behaves in such a way to minimize the confusion for experienced users.
It is fully object-oriented programming language. Everything is an object in Ruby. Each and every code has its properties and actions. Here properties refer to variables and actions refer to methods.
Brief History
Designed by: Yukihiro Matsumoto
The name “Ruby” originated during a chat session between Matsumoto and Keiju Ishitsuka. Two names were selected, “Coral” and “Ruby”. Matsumoto chose the later one as it was the birthstone of one of his colleagues.
- The first public release of Ruby 0.95 was announced on Japanese newspaper on December 21, 1995. Within the next two days, three more versions were released.
- Ruby was localized to Japan. To expand it, the Ruby-Talk, first English language Ruby mailing list was created.
- In 2001, the first Ruby book “Programming Ruby” was published. After its publishment, learners of Ruby throughout the world increased.
- In 2005, they released their first Ruby framework “Ruby on Rails”. The framework release was a big success and the Ruby community increased incredibly.
- Ruby 1.8.7 was released in May 2008. At this point, Ruby was at its peak so much that even Mac OS X began their shipping with built-in Ruby.
- Ruby 2.7.0 was released on Christmas Day in 2019. (Last Release)
- Pattern Matching (experimental)
- REPL improvement
- Compaction GC
- Separation of positional and keyword arguments
Features
1. Object-Oriented
Ruby is purely object-oriented programming language. Each and every value is an object. Every object has a class and every class has a superclass. Every code has its properties and actions. Ruby is influenced by Smalltalk language. Rules applying to objects apply to the entire Ruby.
2. Flexibility
Ruby is a flexible language as you can easily remove, redefine or add existing parts to it. It allows its users to freely alter its parts as they wish.
3. Mixings
Ruby has a feature of single inheritance only. Ruby has classes as well as modules. A module has methods but no instances. Instead, a module can be mixed into a class, which adds the method of that module to the class. It is similar to inheritance but much more flexible.
4. Visual appearance
Ruby generally prefers English keyword and some punctuation is used to decorate Ruby. It doesn’t need a variable declaration.
5. Dynamic typing and Duck typing
Ruby is a dynamic programming language. Ruby programs are not compiled. All class, module and method definition are built by the code when it runs.
Ruby variables are loosely typed language, which means any variable can hold any type of object. When a method is called on an object, Ruby only looks up at the name irrespective of the type of object. This is duck typing. It allows you to make classes that pretend to be other classes.
6. Variable constants
In Ruby, constants are not really constant. If an already initialized constant will be modified in a script, it will simply trigger a warning but will not halt your program.
7. Naming conventions
Ruby defines some naming conventions for its variable, method, constant and class.
- Constant: Starts with a capital letter.
- Global variable: Starts with a dollar sign ($).
- Instance variable: Starts with a (@) sign.
- Class variable: Starts with a (@@) sign.
- Method name: Allowed to start with a capital letter.
8. Keyword arguments
Like Python, Ruby methods can also be defined using keyword arguments.
9. Method names
Methods are allowed to end with a question mark (?) or exclamation mark (!). By convention, methods that answer questions end with question mark and methods that indicates that the method can change the state of the object end with an exclamation mark.
10. Singleton methods
Ruby singleton methods are per-object methods. They are only available on the object you defined it on.
11. Missing method
If a method is lost, Ruby calls the method_missing method with the name of the lost method.
12. Statement delimiters
Multiple statements in a single line must contain semicolon in between but not at the end of a line.
13. Keywords
In Ruby, there are approximately 42 keywords which can’t be used for other purposes. They are called reserved words.
14. Case Sensitive
Ruby is a case-sensitive language. Lowercase letters and uppercase letters are different.
Applications
Ruby can help businesses with web applications, e-commerce, content management, custom database solutions, and prototyping.
Practical things can do with Ruby:
- Business Applications
- Full-stack web development
- Web scraping & crawling
- Static website generators
- Command-line media player (using FFI + libVLC) & other command-line tools
- Automation, Backup & DevOps tools
- Servers
- Parsing, data cleaning & filtering
- API Clients (like Twitter or Github)
- Report generators (PDF, HTML, CSV)