From Python To Ruby
Python and Ruby are the most popular programming languages for developers building web-apps. Both of these programming languages have a large community using them.
Coming from a Python background i did not find it hard to switch to ruby as both these languages are quite similar ( yet very different in their own ways). Just like Python, Ruby has a readable syntax which makes the switching process painless. However you really need practice and time to master ruby.
What makes Ruby easy to learn?
The similarities between the two languages makes it easy to learn and understand.
- No special lines terminators (except the usual newline).
- Readability of syntax makes it easy to learn.
3. Arrays work the same way in both the languages.
4. Embedded document tools are present. Ruby has a repository called Rubygems and Python has a repository called the Package Index that you can use to add cool features to you web applications.
5. Everything is an object, and variables are just references to objects. Python has types whereas Ruby has class; however, the types or class are linked not to the variable names but to the objects themselves.Everything is an object means every entity has some metadata (called attributes) and associated functionality (called methods). These attributes and methods are accessed via the dot syntax.
In the following example ‘type()’ is used in Python to find the class of ‘x’ whereas for the same ‘.class’ is used in Ruby.
6. Brackets are for list, and braces for dictionaries or hashes in case of ruby.
These are just few to list here , there are more similarities between Python and Ruby.
How Is Ruby Different?
Multiple Inheritance: Unlike Python, Ruby does not support the concept of multiple inheritance, it uses mixins for that purpose. Mixins in Ruby allows modules to access instance methods of another one using include method.
Mixins provides a controlled way of adding functionality to classes. The code in the mixin starts to interact with code in the class. In Ruby, a code wrapped up in a module is called mixins that a class can include or extend. A class consist many mixins.
A few more examples are listed below in table:
I have mentioned a few differences here but there are many more to list. Switching from Python to Ruby is not difficult if you understand the similarities and differences between the two languages properly and of course most importantly keep practising.