24
自自自自 自自自自自 自自自 自自自自自自自自 ・・ 自自自自自Nguyễn Văn Đức 自自自自自自 : 自自 自自23 自 自自 自自自自自自自 自自 自自自自自 :、 PC 自自自

Have fun-with-ruby

Embed Size (px)

Citation preview

Page 1: Have fun-with-ruby

自己紹介

名前: 日本語: グエン・ヴァン・ドゥック ベトナム語: Nguyễn Văn Đức

ニックネーム : レン年齢: 23 際大学:ハノイ工科大学趣味:スポーツ、 PC ゲーム

Page 2: Have fun-with-ruby

Get start

Page 3: Have fun-with-ruby

Have fun with Ruby

Page 4: Have fun-with-ruby

Table of contents

1.Ruby in normaly

2.How to program Ruby without using any numbers or letters

3.Summary

Page 5: Have fun-with-ruby

1.Ruby in normaly

Page 6: Have fun-with-ruby

1.Ruby in normaly

階乗 n! を計算する1. Variable2. Method3. Number value4. String5. Structure6. Output

Page 7: Have fun-with-ruby

2. How to use Ruby without using any numbers or letters

Page 8: Have fun-with-ruby

1. Variable

In the normal case

my_number = 2

Without using letter Ruby に「 _ 」とか「 $ 」などでVariable が作られます my_number = 2

<=> _ = 2

2. How to use Ruby without using any numbers or letters

Page 9: Have fun-with-ruby

2. How to use Ruby without using any numbers or letters

2. Numberpid -> Integer

カレントプロセスのプロセス ID を返します。変数 $$ の値と同じです。$$ の値はいつも != 0

+,-,x,/, << で任意ナンバーが作られます。$$ / $$ = 1 $$ - $$ = 0

Page 10: Have fun-with-ruby

2. How to use Ruby without using any numbers or letters

2. Numbermy_number = 2 は _ = $$ / $$ + $$ / $$ になります。

Page 11: Have fun-with-ruby

2. How to use Ruby without using any numbers or letters

3. Stringmy_string = "basic"

"basic" = "b" << "a" << "s" << "i" << "c"

ASCII に基づけ ASCII コードを使って、 String が作られます。"b" << "a" << "s" << "i" << "c" <=> '' << 98 << 97 << 115 <<105 << 99

Page 12: Have fun-with-ruby

2. How to use Ruby without using any numbers or letters

3. String結果:__ = '' << 98 << 97 << 115 <<105 << 99

Page 13: Have fun-with-ruby

2. How to use Ruby without using any numbers or letters

4. Method

メソッドの理想 “package code first, call it later”

Proc とほぼ一緒です。 my_proc = Proc.new{|x| x + 1; p x} ... # more code my_proc.call(2) #=> 3

Page 14: Have fun-with-ruby

2. How to use Ruby without using any numbers or letters

4. Method文字と数字を削除する_ = $$/$$___ = Proc.new{|__| __ + _; p __}

... # more code

___.call(_+_) #=> 3

my_proc = Proc.new{|x| x + 1; p x} ... # more code my_proc.call(2) #=> 3

Proc.new の代わりに、 -> シンボルが作られます。call 使わず、 [] シンボルが作られます。

Page 15: Have fun-with-ruby

2. How to use Ruby without using any numbers or letters

4. Method結果:

_ = $$/$$

___ = -> {|__| __ + _; p __}

... # more code

___.[(_+_)] #=> 3

my_proc = Proc.new{|x| x + 1; p x} ... # more code my_proc.call(2) #=> 3

ほぼ完了しました。

Page 16: Have fun-with-ruby

2. How to use Ruby without using any numbers or letters

5. Structureどんな言語でも、 Structure の種類は3つがあります。

1. Sequence

2. Selection

3. Iteration

Page 17: Have fun-with-ruby

2. How to use Ruby without using any numbers or letters

5.1. Sequencesequence では , 普通な実装です。上から下までで実行します。

=> 問題ない。

Page 18: Have fun-with-ruby

2. How to use Ruby without using any numbers or letters

5.2. Selection

文字禁止なので、 if-esle が使えない。だが、 if-else の代わりに、?:のシンタックスで置き換えることができます

Page 19: Have fun-with-ruby

2. How to use Ruby without using any numbers or letters

5.3. Interation

ループを作るために、再帰と Proc シンタックスを兼ねる。。普段: (1..10).each do |x|

p xend

(___ = -> { x += 1 p x x <= 10 ? ___[] : 0})[]

Page 20: Have fun-with-ruby

2. How to use Ruby without using any numbers or letters

6. Output今まで、結果を表示するために、 puts のコマンドを作っています。Ruby に $> シンボルは puts の使い方と同じです。puts "basic" <=> $> '' << 98 << 97 << 115 <<105 << 99 # => basic

Page 21: Have fun-with-ruby

3. Summary

3.1 Example

Page 22: Have fun-with-ruby

3. Summary

3.1 Example

Page 23: Have fun-with-ruby

3. Summary

3.2. Summary

for Fun and Not Much Else!!

Page 24: Have fun-with-ruby

3. Summary

ご清聴ありがとうございます。