Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
はじめてのRuby 第1章 / Ruby Practice 01
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
muttan
October 18, 2016
Programming
300
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
はじめてのRuby 第1章 / Ruby Practice 01
はじめてのRuby(第五版)勉強会第一回用スライド
muttan
October 18, 2016
Transcript
30 slides
はじめてのRuby 第1章
参考書 たのしいRuby 第5版(SBクリエイティブ) \2,808(Amazon) 大事な(と思われる) 部分を抜粋してやります.
Rubyのバージョン Rubyは2016.10.5現在最新の2.3.1を利用し ます. ダウンロードはこちらから https://www.ruby-lang.org/ja/downloads/ 最新のRubyの情報は、公式HPをチェック https://www.ruby-lang.org/ja/
Rubyの特徴
Rubyの特徴 オブジェクト指向言語である. ソフトウェア工学の前にやるべきだった. スクリプト言語である. Cと違ってコンパイルを挟まずに実行可能. マルチプラットフォームな言語である. OS
XでもLinux, FreeBSDでもWindowsで も実行可能である.
第1章 はじめてのRuby
1.1 Rubyを実行する. rubyコマンドを利用する. hoge.rbというファイルを作成し、 として実行する。 irbを利用する. 対話的に実行する. irbは(Interactive
Rubyの略) $ruby hoge.rb
(Rubyコマンドを利用して) お約束のアレから スタート
helloruby.rb print(“Hello, Ruby.\n”) $ruby helloruby.rb 上記1文を記述し、以下のように実行 p4 helloruby.rbを実際に実行
実行
irbコマンドで実行 $irb irb(main):xxx> print(“Hello, Ruby.\n”) Hello, Ruby. =>nil irb(main):xxx> Hello,
Ruby : 出力 nil : print文の戻り値
1.3 文字列 改行文字 \nは改行を表す. エスケープシーケンスを表示する Hello, “Ruby” のような文字列を出力するときは、
のようにする必要がある. print("Hello, \"Ruby\".\n")
エスケープシーケンスを表示 式 表示される文字列 print("Hello, \"Ruby\".\n") Hello, “Ruby”. print("Hello, \\nRuby.\n") Hello,
\nRuby. print("Hello, \'Ruby\'.") Hello, ‘Ruby’. print("Hello, \\Ruby\\.") Hello, \Ruby\.
1.3.2 “ ”と’ ’の違い “ “の挙動は先ほど説明した通り. ‘ ‘(シングルクォーテーション)で文字列を
囲んだとき、エスケープシーケンス(\n, \t 等々)は解釈されず、そのまま表示される. は、 と表示される. print(‘Hello, \nRuby\n.\n’) Hello, \nRuby\n.\n
1.4 メソッドの呼び出し 括弧は省略可能 print(“d(^_^o)”)とprint “d(^_^o)” は同じ. カンマで並べて表示. と書くことで、“しまもん”と表示される.
print “し“, ”ま“, ”も”, “ん”
1.6 pメソッド デバッグに便利なメソッド puts “100”とputs 100の出力結果は変わら ないが、p “100”とp 100では異なる(文字
列と整数)ことがわかる。 式 結果 puts “100” 100 puts 100 100 p “100” “100” p 100 100 p13 puts_and_p.rbを実際に実行
実行
1.9 変数 変数名 = オブジェクトという形で書く. 変数名はわかりやすく shimamon =
"d(^_^o)" n = 10 p20 area_volume.rbを実際に実行
実行
1.9.1 変数の展開 P20 area_volume.rbにおいて、areaという 変数を出力したい場合、 と書くことができるが、 とすることで、文字列内に変数の値を展開す ることができる. print
“表面積=“, area, "\n" print “表面積=#{area}\n“
1.9.1 変数の展開 x = 10 y = 20 z =
30 area = (x * y + y * z + z * x) * 2 volume = x * y * z print “表面積=#{area}\n" print “体積=#{volume}\n" P20 area_volume2.rb
1.10 コメントアウト 1行コメントアウトするときは、#を先頭に 記述する. コメントが複数行にわたる場合は、 ”=begin”と”=end”で囲む必要がある.
1.10 コメントアウト =begin foo bar コメントブロック =end x = 10
y = 20 z = 30 # 表面積 area = (x * y + y * z + z * x) * 2 # 体積 volume = x * y * z print “表面積=#{area}\n" print “体積=#{volume}\n"
1.12 条件判断(if…then…end) 条件分岐させるために使用する. thenは省略可能です. if condition then expression
end p25 greater_smaller.rbを実際に実行
実行
1.12 条件判断(if…then…end) elseもあります if condition then expression else expression
end p26 greater_smaller_else.rbを実際に実行
実行
1.13 繰り返し(while文) Cと同じ構文です. while condition expression end p26 例を実際に実行
実行
1.13 繰り返し(timesメソッド) 所謂イテレータと言われるもの. あとで詳しくやるのでこんなものがあるぐら いでOK. obj.times do expression
end
More Decks by muttan
See All by muttan
さわやか待ち時間LINE botを作った話 / Sawayaka LINE bot
bath_poo_
0
150
コンテナ開発入門 1回目/Introduction to Container Development 1
bath_poo_
0
260
ISUCONってなんだ / What is ISUCON
bath_poo_
0
420
Web技術の基本 8回目 / Introduction to Web technologies 8th class
bath_poo_
0
260
Web技術の基本 7回目 / Introduction to Web technologies 7th class
bath_poo_
0
260
Web技術の基本 6回目 / Introduction to Web technologies 6th class
bath_poo_
1
300
Web技術の基本 5回目 / Introduction to Web technologies 5th class
bath_poo_
0
190
Web技術の基本 4回目 / Introduction to Web technologies 4th class
bath_poo_
0
260
Web技術の基本 3回目 / Introduction to Web technologies 3rd class
bath_poo_
0
280
Other Decks in Programming
See All in Programming
作れるエンジニアから、価値を届けるエンジニアへ
ryunakayama
1
1.4k
観測者から当事者へ、AI 時代にドメインへ深入りする知識と技術 / From Observer to Practitioner: Going Deep into Domains in the Age of AI
nrslib
5
2.4k
Distance field of Julia set
kinakomoti321
0
340
Canvas 2D Context Next
petamoriken
1
1.1k
imagewebp()の向こう側: WebPはなぜ JPEG・PNGより軽いのか
yuzneri
0
160
将来の標準フォーマッター?ktfmtを深堀る
t45k
1
260
疎結合とは何か?ソフトウェア設計における結合バランスについて考える #phpcon_niigata
kajitack
2
450
どうしても Eloquent でリポジトリパターンをやりたいんだ #phpcon_niigata / phpcon-niigata-2026
shogogg
0
720
Engineering Biometric UX Across Android Versions | DroidKnights 2026
ryunen344
1
220
Agentic AI with the Power of Jakarta EE
ivargrimstad
0
270
DroidKnights 2026 Android A2UI Jetpack Compose 기반의 안전한 AI UI 렌더링 - 박제창
itsmedreamwalker
1
280
AIと速く作れる時代に、要求と設計をどう確かめるか ーイベントストーミングとSDDの実践ー
syobochim
0
230
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Technical Leadership for Architectural Decision Making
baasie
4
660
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
73
43k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
510
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
350
Making the Leap to Tech Lead
cromwellryan
135
10k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
660
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.7k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
1.1k
Heart Work Chapter 1 - Part 1
lfama
PRO
11
37k
Docker and Python
trallard
47
4.3k