From 31815c65933525e79b8a695cfd67d200c1915a37 Mon Sep 17 00:00:00 2001 From: Ahmad Hamdani Date: Mon, 24 Oct 2016 23:57:15 +0700 Subject: [PATCH 1/3] Update content --- Readme.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Readme.md b/Readme.md index 59745f4..60c746a 100644 --- a/Readme.md +++ b/Readme.md @@ -21,9 +21,11 @@ install ruby dengan perintah `sudo apt-get install ruby` * Arrays * Code Blocks * Ranges +* Iterator * Regular Expressions * Symbols * Hashes +* Date & Time ## Session 2: OOP with Ruby @@ -44,6 +46,7 @@ install ruby dengan perintah `sudo apt-get install ruby` * Classes as Objects * Metaprogramming * I/O +* Multithreading ## Session 4: Testing From 3e740c5dfeb990ddfcd14023353ad52c0f670bcd Mon Sep 17 00:00:00 2001 From: Ahmad Hamdani Date: Tue, 25 Oct 2016 00:55:18 +0700 Subject: [PATCH 2/3] Added content I added content about basic Iterator --- Session1.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Session1.md b/Session1.md index b640ef0..d7a611d 100644 --- a/Session1.md +++ b/Session1.md @@ -537,6 +537,18 @@ else end ``` +## Iterator +Iterator merupakan salah satu fitur yang didukung oleh collections dalam ruby. collections merupakan object yang menyimpan sekumpulan data, seperti array dan hashes. + +``` +array = ["a", "b", "c", "d"]; +array.each do |i| + puts i +end +``` + +Tiap nilai dari array disimpan dalam i dan ditampilkan ke console melalui puts. + ## Regular Expressions _Regular Expression_ dalam ruby ditangani oleh kelas `Regexp`. From 46e8bd9ceb4c09a96e91aa70eb3bbe2a51ed116a Mon Sep 17 00:00:00 2001 From: Ahmad Hamdani Date: Tue, 25 Oct 2016 00:59:19 +0700 Subject: [PATCH 3/3] Added content --- Session3.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Session3.md b/Session3.md index 273bd9f..2b66603 100644 --- a/Session3.md +++ b/Session3.md @@ -304,3 +304,43 @@ end unless file.closed? file.close ``` + +## Multitreading + +Program multithreading adalah program yang memiliki banyak thread yang dieksekusi. +Dalam thread tiap block code dieksekusi secara sequential tapi thread sendiri bisa dieksekusi secara parallel dalam multicore cpu. + +cara membuat thread di ruby: +Thread.new + +cara membuat multithreading : + +```ruby +#!/usr/bin/ruby + +def func1 + i=0 + while i<=3 + puts "func1" + sleep(1) + i=i+1 + end +end + +def func2 + j=0 + while j<=3 + puts "func2" + sleep(2) + j=j+1 + end +end + +t1=Thread.new{func1()} +t2=Thread.new{func2()} +t1.join +t2.join +puts "" +``` + +selengkapnya di : https://www.tutorialspoint.com/ruby/ruby_multithreading.htm