List of things I used without understanding well: Ruby

Introduction

The purpose of this article is to deepen my own understanding by summarizing "what I used without knowing it" while I was studying. It is listed below.

Ruby edition

① Character code specification

In a program file such as Ruby, the character code may be specified by writing the following code at the beginning.

sample1.rb


 # -*- encoding: utf-8 -*-

This is called a ** magic comment **. I inserted it every time I thought I needed it. However, ** UTF-8 is used by default in Ruby 2.0 and later **, so there is no need to specify UTF-8 in current Ruby.

I think the reason I wrote magic comments every time was because I was referring to the code that used the one before Ruby 2.0.

② About ruby gems

You'll occasionally see lines like this in Ruby code.

sample2.rb


 require "rubygems"

In the first place, rubygems is a system that helps create, publish, and install libraries in Ruby. In previous Ruby, when writing a program that uses a module installed as a gem, it was necessary to first execute require for rubygems. However, since ** Ruby 1.9, the rubygems module has become part of the standard library **, so there is no need to bother to require rubygems.

I think the reason I wrote this was because I was referring to the code that used Ruby 1.8 or earlier.

Summary and impressions

While referring to various codes for studying, I realized that some of them were actually used even though they were unnecessary. I've also learned that some languages are no longer needed because of language updates, so I'll be aware of the language versions used in the code I've included in the future.

Recommended Posts

List of things I used without understanding well: Ruby
[Ruby] List of basic commands
List of methods used when manipulating strings
[Note] A list of commands that I checked many times after trying Ruby.
I used it without knowing the O / R mapping of rails, so I checked it.
List of methods used in PAIZA D rank
A collection of RSpecs that I used frequently
I checked the number of taxis with Ruby