pctechguide.com

  • Home
  • Guides
  • Tutorials
  • Articles
  • Reviews
  • Glossary
  • Contact

Guide to Learning Ruby in 2019

Ruby is currently one of the 10 most popular programming languages on the market. It is used in an estimated 2.7% of all websites, although this figure is growing year by year.

First of all, I want to clarify that the reason for this article is not to convince you that Ruby is a better language than others. The purpose is to illustrate some characteristics that might interest you if you want to learn the Ruby language.

Ruby is a language I work with every day, but I don’t consider myself an expert. I know some things I found interesting to share, if some Ruby expert wants to correct some of the code I write here, I would appreciate it. If you want to add things, that would be great too.

Ruby is a language that focuses more on the developer than the machine. This means two things:

  • The syntax is very friendly and reads almost like natural language.
  • The performance is not the same as in lower level languages.

This does not mean that Ruby is a poor performance language, since it is used in applications (especially web) that handle many requests per second (like Basecamp). But there is a difference between the execution time of Ruby and other languages such as C++, JAVA and not to mention C.

Ruby is very popular in web applications because there is Ruby on Rails a very popular framework to make web applications that one day used or continue to use sites like Twitter, Github, Airnbn and SoundCloud. Rails is the most popular web framework in the Ruby community, although there are also others like Sinatra. In Ruby you can also create desktop applications, as it is multi-platform, plus you can write mobile applications for different platforms with RubyMotion.

After a little introduction to the language, let’s talk code about Ruby.

EVERYTHING IS AN OBJECT (ALMOST)

Ruby is an object-oriented language, such as JAVA, C++, Python, etc. With the characteristic that Ruby takes very seriously its role on being object-oriented. In Ruby, for example, there are no primitives, like int, everything is an object, even operators like +, < are objects.

What is not an object in Ruby? Blocks, although they can be (what!), flow controls like if else while and some others, are not objects either, {and } they are not objects either.

Is this interesting? Personally it is, for example you can execute methods on what in other languages would be primitive, something like converting a number to string:

In Ruby

number = 1

number.to_s

In JAVA(for example)

int number = 1;

Integer.toString(number);

YOU CAN ABOUT WRITING THE LANGUAGE.

This is interesting, although in the real productive world I don’t know how much it is used, but here it goes. Imagine that for some strange reason you want to over write the method that converts integers to strings, you could do something like that:

class Fixnum

  def to_s

    self + 1

  end

end

1.      to_s # Returns 2 instead of “1”

If you used this syntax, you have overwritten a method of a language class to make it work the way you want. In this case, instead of converting the value to string, it adds a 1 😛

Note, this only applies to the execution of your program, so don’t be afraid to ruin your interpreter.

THE SYMBOLS

This section was added at the recommendation of @IvanChukitow on Twitter, so stop by and thank him for giving his feedback during my Twitter conversation with him!

In Ruby we have symbols, they are written like this :symbol_name and they are, chains not mutable, that is to say that the differences with a String are that they cannot change their value, unlike strings, which can.

Symbols are a very particular feature of Ruby and I don’t know if they are used in other languages as such. What are they for? In the first place they are used when you are declaring a string that is not going to change, in the second place they have a much higher performance than a normal String by… let’s see some code before we explain why:

:hello_wordo.object_id == :hello_wordo.object_id #True

“hello world”.object_id == “hello world”.object_id # False

Let’s analyze the code we just wrote. First of all, we are not comparing the strings as such, because in that case “hello world” == “hello_world” is true. We are instead comparing the object ID, an ID that Ruby uses to identify the object in memory.

Why does one give true and the other false? Because when Ruby sees 2 identical symbols he doesn’t create another object, if he didn’t refer to the one already created, while in chains, Ruby doesn’t know if 2 chains “say the same thing” so he keeps creating more objects in memory per string we create.

This translates into better language performance, basically executions with strings are slower than with symbols.

Filed Under: Articles

Latest Articles

Mobile Intel Pentium MMX technology guide

In January 1997 the first mobile Pentiums with MMX technology appeared, clocked at 150MHz and 166MHz. Initially these were built on Intel's enhanced 0.35-micron CMOS process technology with the processor's input and output pins operating at 3.3 volts … [Read More...]

Scheduling Tasks Cleanup

Open up the Scheduled Tasks tool from the Start menu, either via Programs > Accessories > System Tools ... ... or via Settings > Control Panel > Scheduled Tasks. It's likely that some tasks have already been automatically set up, either by Windows or applications that … [Read More...]

Figuring Out Which iPAd Model You Have

iPads are peculiar. They may look the same on the outside, but they operate very differently. We're going to show you how you can differentiate each iPad according to some of its features. Thanks to this, we will be able to identify which is our iPad, something that will help us, for example, if … [Read More...]

Revolutionize Your Internet Experience with Orbi 960 – The Ultimate WiFi System

In a world where seamless connectivity is essential, slow and unreliable internet connections are a major problem. Whether you are running a business, … [Read More...]

Do You Need a VPN When Trading Cryptocurrency?

There’s no doubt that the biggest global industries in 2023 are tech-driven, while there remains a significant crossover between many of these … [Read More...]

Goodbye Bitcoin: the 3 alternative cryptocurrencies that have great upside potential, according to experts

Bitcoin has been a very lucrative investment for people that got into it early. One report from The Motley Fool pointed out that $10 of bitcoin … [Read More...]

Self-driving cars face their Achilles’ heel and may be targets of hackers

The market for self-driving cars is booming. Customers spent $22.22 billion on these autonomous vehicles in 2021 and they will likely spend more in … [Read More...]

How to avoid scams with bitcoin and other cryptocurrencies

Cryptocurrencies got a bad reputation when scams multiplied like ants on a piece of cake. Even today many people associate bitcoin and other … [Read More...]

WHAT IS CLOUD COMPUTING AND WHAT ARE ITS MAIN BENEFITS?

Users are Increasingly using cloud computing to store their information, which is replacing local storage. The business digitization process goes … [Read More...]

Guides

  • Computer Communications
  • Mobile Computing
  • PC Components
  • PC Data Storage
  • PC Input-Output
  • PC Multimedia
  • Processors (CPUs)

Recent Posts

Disk Keeper 2017 Pro Premier Reviews

PROS: Disk Keeper 16 Pro Premier Review for servers and high performance personal computers. CONS: The results of the Disk Keeper 16 Pro Premier … [Read More...]

Avoid the Lazy Web Security Path

Credit: kutubQ via Canva Be lazy now, work much harder later; it is as simple as that. Web security laziness and related complacency are much too … [Read More...]

Ethernet

Ethernet was developed in the mid 1970s by the Xerox Corporation, and in 1979 Digital Equipment Corporation DEC) and Intel joined forces with Xerox to … [Read More...]

[footer_backtotop]

Copyright © 2023 About | Privacy | Contact Information | Wrtie For Us | Disclaimer | Copyright License | Authors