[RUBY] Special Lecture on Multi-Scale Simulation: I tried to summarize the 7th

!ruby-2.5.5p157

Introduction

Since qiita often uses Markdown, I will leave the qiita article below for notes. Markdown Writing Cheat Sheet

Course content

Convention over Configuration

Details of Configuration over Configuration

shebang

This time, shebang was explained.

What is a shebang? shebang is the first line of a UNIX script that starts with #! And specifies the interpreter to start and load the script.

About setting of path

If the path is set, it can be converted into a command, and the program can be handled conveniently.

How to pass the path to the shell config file

  1. emacs ~ / .bashrc ← Change to another configuration file except bash
  2. export PATH=".:~/bin:$PATH"
  3. source ~/.bashrc

With this setting, programs under ~ / bin can be easily used if you have execute permission! !!

Use the chmod command for execution privileges. You can check the contents with man chmod </ strong>.

Ruby syntax

Ruby handles if-else statements as follows

if expression[then]
formula...
[elsif expression[then]
formula... ]
...
[else
formula... ]
end

Class review 1

--How to handle if-else statements in ruby

p year = ARGV[0].to_i
# .to_i is a method to convert to int type
if year % 4 == 0
  p true
end

Class review 2

--How to handle arrays and loop statements in ruby

[2004, 1999].each do |year|
# []Array (same as python list)
#Extract elements in order with each method
  p year
  if year%4 == 0
    p true
  else
    p false
  end
end

Class review 3

--More detailed loop statement


[1900,2004,1999].each do |year|
  p year
  #The first if statement
  if year % 100 ==0
    p false
    next #next is the same as the python continue statement
  end 

  #Second if statement
  if year % 4 == 0
    p true
  else
    p false
  end
end

  • source ~/Downloads/git/grad_members_20f/members/taiseiyo/memos/class7.org

Recommended Posts