Gems
Learn what gems are and how to use them in Ruby.
We'll cover the following...
What are gems?
Until now, all of our experiments have been quite straightforward. However, with two-dimensional arrays, we may have noticed the lack of visual cues. For example, the array for the “Sea Battle” game doesn’t look very intuitive in the console:
$ irb
> Array.new(10) { Array.new(10) }
=> [[nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil], [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]]
We still can understand what it is, but can we quickly find out the fifth row and second column? It would help if we looked closely enough.
Ruby language designers knew that it was impossible to create something that everyone would like. Instead of having a fixed set of tools, it was decided that they would introduce extensions so that everyone could add something new to the language.
Software developers from around the world took advantage of this opportunity and built an amazing ecosystem of extensions: gems. You may have already heard about gems, especially if you know how to write code in other languages, where they are also called libraries or packets. They work similarly: for example, ...