to_ ○

to_○

x = 50
y = "3"

p x + y.to_i #to int
p x + y.to_f #to floo


scores = {keiichi:400, tomomi:2000}

p scores.to_a #to arry 
p scores.to_h #to hassh 

%notation


puts ("red", "blue")

puts %(hello) #You can use "" between OK

p ["red", "blue"]

p %W(red, blue) #OK

if


score = gets.to_i


if score > 80 then
        puts "great!"
else if score > 60 then
    puts "good"

else
    puts "so so..."

end

case

#case

signal = gets.chomp #Chomp to remove the last newline code

case signal
when "red" 
    puts "stop!"
when "green" 
    puts "go!"
when "yello" 
    puts "caution!"
    
else
    puts "wrong signal"

end

While

#while

i = 0

while i < 10 do
    
    puts "#{i}: hello" # #{i}Is used to make it easier to see the number of times
    
    i += 1 #i = i +Can be shortened to 1
    
end

Times

#times

10.times do |i| #i +=Same effect as 1
    puts "hello"
end

for


for i in 15..20 do
    p i
end

for color in ["red", "blue"] do
    p color
end

for name, score in {taguchi:200, fkoji:400} do
    puts "#{name}: #{score}"
end

for color in %W(red, bule) do
    p color
end

each


(15..20).each do |i|
    p i
end

["red", "blue"].each do |color|
    p color
end

{taguchi:200, fkoji:400}.each do |name, score|
    puts "#{name}: #{score}"
end

%W(red, bule).each do |color|
    p color
end

Recommended Posts

to_ ○
Association (1 to 1)! !!
Reintroduction to JSTL
to rewrite unless
Introduction to SWING
Method to search
How to deploy
Introduction to web3j
Introduction to Micronaut 1 ~ Introduction ~
[Java] Introduction to Java
Introduction to migration
Corresponds to 17 arrays
Introduction to java
Corresponds to Scope
Corresponds to 15 strings
Introduction to Doma
8 Corresponds to multiple arguments
Add files to jar files
How to develop OpenSPIFe
Introduction to JAR files
Changes from Java 8 to Java 11
Sum from Java_1 to 100
Try to release gem
How to call AmazonSQSAsync
Introduction to Ratpack (8)-Session
How to use Map
Steps to deploy to Heroku
Class to take count
How to write Rails
How to use rbenv
Migrate from JUnit 4 to JUnit 5
Introducing CircleCI to Rails
Introduction to RSpec 1. Test, RSpec
Introducing Bootstrap to Rails 5
How to use letter_opener_web
URL to String conversion
How to use fields_for
How to use java.util.logging
Introduction to Ratpack (6) --Promise
Set RSpec to DRY
How to use map
Introducing Bootstrap to Rails !!
Introduction to Ratpack (9) --Thymeleaf
[Java] Connect to MySQL
Swipe to switch screens
How to use collection_select
PATH to use docker-slim
Introduce Vue.js to Rails
Steps to deploy Struts 2.5.8
Introduction to PlayFramework 2.7 ① Overview
How to adapt Bootstrap
Introduction to Android Layout
To debug in eclipse
How to use Twitter4J
Road to REPL (?) Creation (3)
How to use active_hash! !!
How to install Docker
How to use MapStruct
Introduction to design patterns (introduction)
How to use hidden_field_tag
How to use TreeSet