SlideShare a Scribd company logo
2
Most read
4
Most read
5
Most read
Ruby
Programming Language
Introduction
28 Jun 2015
Kwangshin Oh
kwangshin@gmail.com
http://kwangshin.pe.kr
Seven Languages in Seven Weeks
A Pragmatic
Guide to
Learning
Programming
Languages
By Bruce A. Tate
Why New Programming Language?
“Learning a new programming language will show you
new ways of thinking, and new approaches to problem solving
that will help you be a better programmer in any language.”
- Pragmatic Bookshelf
“Ultimately, programming is about understanding, and
understanding is about ideas. So, exposure to new ideas is essential
to a deeper understanding of what programming is all about.”
- Foreword By Joe Armstrong, creator of Erlang
Agenda
 Ruby is…
 History & Why?
 With a Spoonful of Sugar
 So, Ruby is…
 Ruby: Interpreted Language
 Ruby: Interpreted Language – Example
 Compare: Compiled Language - Java
 Ruby: Object-Oriented Language
 Ruby: Pure Object-Oriented Language
 Ruby: Dynamically Typed Language
 What is Duck Typing?
 Ruby: Duck Typing Code Example
 Download & Installation
 Ruby Code
 Reference
Ruby is…
 Programming Language!
Dynamic
Open Source
 Focus on…
Simplicity
Productivity
 Has an elegant syntax
Natural to read
Easy to write
Image Source: Ruby Programming Language
History & Why?
 Ruby’s Creator
Yukihiro “Matz” Matsumoto
 Created in about 1993
 Motivation
The primary motivation was to amuse himself!
Just a hobby at the beginning
New object-oriented language that combines
characteristics from Lisp, Smalltalk and Perl
To enhance programmers’ productivity
“Ruby is simple in appearance, but is very complex inside, just like our human body.”
- Matz, speaking on the Ruby-Talk mailing list, May 12th, 2000.
Image Source: Ruby Everywhere
With a Spoonful of Sugar
 Ruby with more syntactic sugar
Makes code easier to read and write
 Focus on the efficiency of the
programmers
“A spoonful of sugar makes the medicine go down.”
Mary Poppins
Image Source: Disney Wiki – A Spoonful of Sugar
So, Ruby is…
 Interpreted Language
Ruby code is executed by an interpreter
 Object-Oriented Language
Encapsulation
Inheritance
Polymorphism
 Dynamically Typed Language
Types are bound at execution time
Image Source: Skillcrush - Ruby
Interactive
Console
Ruby File
(*.rb)
Ruby: Interpreted Language
Image Source: http://www.iconsdb.com, http://dryicons.com and http://findicons.com
Ruby
Interpreter
Interactive
Console
Ruby File
(Ha.rb)
Ruby: Interpreted Language - Example
D:Ruby22bin>type Ha.rb
3.Times do
print “Ha “
end
D:Ruby22bin>ruby Ha.rb
Ha Ha Ha
D:Ruby22bin>
D:Ruby22bin>ruby
3.Times do
print “Ha “
end
^D
Ha Ha Ha
D:Ruby22bin>
Compare: Compiled Language - Java
Java Source File
(*.java)
Java
Compiler
Java Class File
(*.class)
JRE
(Java Runtime Environment)
Ruby: Object-Oriented Language
 Encapsulation
[State & Behavior] : Packaged together
 Inheritance
[Class Tree] : Object types are organized
 Polymorphism
[Many Forms]
: Objects can be shown
Image Source: What Is an Object?
Image Source: What Is Inheritance?Image Source: Object-Oriented Concepts
Ruby: Pure Object-Oriented Language
 Ruby Programming Language
Everything is an object!
 Compare: Java Programming Language
Primitive types (int, char, ……) are not objects!
D:Ruby22bin>irb
irb(main):001:0> 4
=> 4
irb(main):002:0> 4.class
=> Fixnum
irb(main):003:0> 4 + 4
=> 8
irb(main):004:0> 4.methods
=> [:to_s, :inspect, :-
@, :+, ∙∙∙∙∙∙, :__id__]
irb(main):005:0>
Ruby: Dynamically Typed Language
Types are bound
at execution time
Flexibility
Execution Safety
 Types are bound
at compile time
 Flexibility
 Execution Safety
Dynamically Typed
Statically Typed
Java
What is Duck Typing?
Quacks
like a duck
Swims
like a duck
Walks
like a duck
Call it
a duck
“When I see a bird that walks like a duck and
swims like a duck and quacks like a duck,
I call that bird a duck.” - James Whitcomb Riley
Image Source: https://www.iconfinder.com and http://www.vectors4all.net/
Ruby: Duck Typing Code Example
D:Ruby22bin>irb
irb(main):001:0> i = 0
=> 0
irb(main):002:0> a = ['100', 100.0]
=> ["100", 100.0]
irb(main):003:0> while i < 2
irb(main):004:1> puts a[i].to_i
irb(main):005:1> i = i + 1
irb(main):006:1> end
100
100
=> nil
irb(main):007:0>
We consider this to_i method as quack!
Duck typing doesn’t care
what the underlying type might be
(whether string or float).
string
float
Download & Installation
 Current Stable Version
 Ruby 2.2.2 (As of 28 Jun 2015)
 Windows
 RubyInstaller - http://rubyinstaller.org/downloads/
 OS X
 Homebrew - http://brew.sh/
 Debian GNU/Linux and Ubuntu
 apt – command : $ sudo apt-get install ruby-full
 CentOS, Fedora, and RHEL
 yum – command :$ sudo yum install ruby
Ruby: Sample Code
D:Ruby22bin>ruby
properties = ['object oriented', 'duck typed', 'productive', 'fun']
properties.each {|property| puts "Ruby is #{property}."}
^D
Ruby is object oriented.
Ruby is duck typed.
Ruby is productive.
Ruby is fun.
D:Ruby22bin>
Ruby Code: Hello World!
D:Ruby22bin>irb
irb(main):001:0> puts 'Hello World!'
Hello World!
=> nil
irb(main):002:0> language = 'Ruby'
=> "Ruby"
irb(main):003:0> puts "Hello, #{language}"
Hello, Ruby
=> nil
irb(main):004:0> language = 'my Ruby'
=> "my Ruby"
irb(main):005:0> puts "Hello, #{language}"
Hello, my Ruby
=> nil
irb(main):006:0>
Ruby’s Interactive Console
<One Quote String>
Interpreted Literally
<Two Quotes String>
String Evaluation
Ruby Code: Comparison Operators
D:Ruby22bin>irb
irb(main):001:0> x = 4
=> 4
irb(main):002:0> x < 5
=> true
irb(main):003:0> x > 4
=> false
irb(main):004:0> false.class
=> FalseClass
irb(main):005:0> true.class
=> TrueClass
irb(main):006:0> puts 'X value is equal to 4.' if x == 4
X value is equal to 4.
=> nil
irb(main):007:0>
Everything is an object
in Ruby!
Ruby Code: Loops – until & while
D:Ruby22bin>irb
irb(main):001:0> x = 5
=> 5
irb(main):002:0> x = x - 1 until x == 1
=> nil
irb(main):003:0> x
=> 1
irb(main):004:0> while x < 5
irb(main):005:1> x = x + 1
irb(main):006:1> puts x
irb(main):007:1> end
2
3
4
5
=> nil
Ruby Code: Expressions - true & false
D:Ruby22bin>irb
irb(main):001:0> puts '1 is true in Ruby' if 1
1 is true in Ruby
=> nil
irb(main):002:0> puts 'String is true in Ruby' if 'Kwangshin Oh'
(irb):2: warning: string literal in condition
String is true in Ruby
=> nil
irb(main):003:0> puts '0 is also true in Ruby' if 0
0 is also true in Ruby
=> nil
irb(main):004:0> puts 'The false is false in Ruby' if false
=> nil
irb(main):005:0> puts 'The nil is false in Ruby' if nil
=> nil
irb(main):006:0>
Everything
( but nil and false )
evaluate to true!
Reference
 Seven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Language
by Bruce A. Tate
 https://pragprog.com/book/btlang/seven-languages-in-seven-weeks
 Ruby Programming Language
 https://www.ruby-lang.org/
 Ruby-Talk mailing list, May 12th, 2000
 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/2773
 Disney Wiki – A Spoonful of Sugar
 http://disney.wikia.com/wiki/A_Spoonful_of_Sugar
 Matzにっき (Matz Diary)
 http://www.rubyist.net/~matz/
 The Java™ Tutorials - Object-Oriented Programming Concepts
 https://docs.oracle.com/javase/tutorial/java/concepts/index.html
 Duck typing
 https://en.wikipedia.org/wiki/Duck_typing

More Related Content

What's hot (20)

PDF
Introduction to Ruby
kim.mens
 
PDF
Ruby Presentation
platico_dev
 
PPTX
Ruby programming
Kartik Kalpande Patil
 
PDF
Let's Learn Ruby - Basic
Eddie Kao
 
PPT
Ruby Basics
SHC
 
ODP
Ruby
Aizat Faiz
 
PPTX
Typescript ppt
akhilsreyas
 
PDF
Ruby on Rails Presentation
adamcookeuk
 
ODP
Introduction to Programming in LISP
Knoldus Inc.
 
PDF
Python quick guide1
Kanchilug
 
PDF
JavaScript Promises
Derek Willian Stavis
 
PDF
Intro to functional programming
Assaf Gannon
 
PDF
Threads concept in java
Muthukumaran Subramanian
 
PPTX
Php internal architecture
Elizabeth Smith
 
PPTX
Lesson 6 php if...else...elseif statements
MLG College of Learning, Inc
 
PPT
SOLID Design Principles
Andreas Enbohm
 
PPTX
Php operators
Aashiq Kuchey
 
PDF
Generic Programming
Muhammad Alhalaby
 
PPTX
Sqlite
Raghu nath
 
PPTX
ArrayList in JAVA
SAGARDAVE29
 
Introduction to Ruby
kim.mens
 
Ruby Presentation
platico_dev
 
Ruby programming
Kartik Kalpande Patil
 
Let's Learn Ruby - Basic
Eddie Kao
 
Ruby Basics
SHC
 
Typescript ppt
akhilsreyas
 
Ruby on Rails Presentation
adamcookeuk
 
Introduction to Programming in LISP
Knoldus Inc.
 
Python quick guide1
Kanchilug
 
JavaScript Promises
Derek Willian Stavis
 
Intro to functional programming
Assaf Gannon
 
Threads concept in java
Muthukumaran Subramanian
 
Php internal architecture
Elizabeth Smith
 
Lesson 6 php if...else...elseif statements
MLG College of Learning, Inc
 
SOLID Design Principles
Andreas Enbohm
 
Php operators
Aashiq Kuchey
 
Generic Programming
Muhammad Alhalaby
 
Sqlite
Raghu nath
 
ArrayList in JAVA
SAGARDAVE29
 

Viewers also liked (20)

PDF
Introduction to Ruby
Ranjith Siji
 
PDF
Ruby on Rails Presentation
Joost Hietbrink
 
PDF
Ruby on Rails for beginners
Vysakh Sreenivasan
 
PDF
Vaporware To Awesome
Yehuda Katz
 
PDF
Feeling Objects: Pattern Matching in Ruby
Ryan Levick
 
PDF
Reflection in Ruby
kim.mens
 
PDF
Lemme tell ya 'bout Ruby
Arvin Jenabi
 
PDF
Ruby Programming Introduction
Anthony Brown
 
PPTX
핀테크 코리아 2014 후기 - 오광신
Kwangshin Oh
 
PDF
Ruby Egison
Rakuten Group, Inc.
 
PDF
Why Ruby
Daniel Lv
 
PPTX
Sapphire Presentation for Review_CPG_Food.PPTX
John V. Counts Sr.
 
PDF
Pure Function and Rx
Hyungho Ko
 
PDF
Akka Fault Tolerance
Hyungho Ko
 
PDF
[Spring Camp 2013] Java Configuration 없인 못살아!
Arawn Park
 
PDF
Sapphire Presentation
usama17
 
PPT
Web Development Ppt
Bruce Tucker
 
PDF
Compose Async with RxJS
Kyung Yeol Kim
 
PDF
java 8 람다식 소개와 의미 고찰
Sungchul Park
 
KEY
Introducing Ruby
James Thompson
 
Introduction to Ruby
Ranjith Siji
 
Ruby on Rails Presentation
Joost Hietbrink
 
Ruby on Rails for beginners
Vysakh Sreenivasan
 
Vaporware To Awesome
Yehuda Katz
 
Feeling Objects: Pattern Matching in Ruby
Ryan Levick
 
Reflection in Ruby
kim.mens
 
Lemme tell ya 'bout Ruby
Arvin Jenabi
 
Ruby Programming Introduction
Anthony Brown
 
핀테크 코리아 2014 후기 - 오광신
Kwangshin Oh
 
Ruby Egison
Rakuten Group, Inc.
 
Why Ruby
Daniel Lv
 
Sapphire Presentation for Review_CPG_Food.PPTX
John V. Counts Sr.
 
Pure Function and Rx
Hyungho Ko
 
Akka Fault Tolerance
Hyungho Ko
 
[Spring Camp 2013] Java Configuration 없인 못살아!
Arawn Park
 
Sapphire Presentation
usama17
 
Web Development Ppt
Bruce Tucker
 
Compose Async with RxJS
Kyung Yeol Kim
 
java 8 람다식 소개와 의미 고찰
Sungchul Park
 
Introducing Ruby
James Thompson
 
Ad

Similar to Ruby Programming Language - Introduction (20)

PDF
Ruby an overall approach
Felipe Schmitt
 
DOCX
Page List & Sample Material (Repaired)
Muhammad Haseeb Shahid
 
PPTX
Ruby for .NET developers
Max Titov
 
PDF
Introduction to Ruby & Modern Programming
Christos Sotirelis
 
PPTX
Ruby introductions
Binh Bui
 
PDF
Ruby tutorial
knoppix
 
KEY
Learn Ruby 2011 - Session 2
James Thompson
 
KEY
Introduction to Ruby
Mark Menard
 
PPTX
Ruby -the wheel Technology
ppparthpatel123
 
PPTX
Ruby for PHP developers
Max Titov
 
PPTX
Ruby basics
Tushar Pal
 
PPTX
How to use Ruby in QA, DevOps, Development. Ruby lang Intro
Viacheslav Horbovskykh
 
ZIP
Meta Programming in Ruby - Code Camp 2010
ssoroka
 
PDF
Moving from C++ to Ruby
Leslie Brown
 
DOC
Pré Descobrimento Do Brasil
ecsette
 
PDF
Workin On The Rails Road
RubyOnRails_dude
 
PDF
ruby_vs_perl_and_python
tutorialsruby
 
PDF
ruby_vs_perl_and_python
tutorialsruby
 
PPTX
Why ruby
Bill Chea
 
Ruby an overall approach
Felipe Schmitt
 
Page List & Sample Material (Repaired)
Muhammad Haseeb Shahid
 
Ruby for .NET developers
Max Titov
 
Introduction to Ruby & Modern Programming
Christos Sotirelis
 
Ruby introductions
Binh Bui
 
Ruby tutorial
knoppix
 
Learn Ruby 2011 - Session 2
James Thompson
 
Introduction to Ruby
Mark Menard
 
Ruby -the wheel Technology
ppparthpatel123
 
Ruby for PHP developers
Max Titov
 
Ruby basics
Tushar Pal
 
How to use Ruby in QA, DevOps, Development. Ruby lang Intro
Viacheslav Horbovskykh
 
Meta Programming in Ruby - Code Camp 2010
ssoroka
 
Moving from C++ to Ruby
Leslie Brown
 
Pré Descobrimento Do Brasil
ecsette
 
Workin On The Rails Road
RubyOnRails_dude
 
ruby_vs_perl_and_python
tutorialsruby
 
ruby_vs_perl_and_python
tutorialsruby
 
Why ruby
Bill Chea
 
Ad

More from Kwangshin Oh (6)

PPT
CS6201 Software Reuse - Design Patterns
Kwangshin Oh
 
PPT
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIs
Kwangshin Oh
 
PPT
CS6270 Virtual Machines - Retargetable Binary Translators
Kwangshin Oh
 
PPT
CS5261 Group 8 Presentation - US Mobile Industry
Kwangshin Oh
 
PPT
Jini Network Technology
Kwangshin Oh
 
PPT
Object-Oriented Programming Concepts
Kwangshin Oh
 
CS6201 Software Reuse - Design Patterns
Kwangshin Oh
 
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIs
Kwangshin Oh
 
CS6270 Virtual Machines - Retargetable Binary Translators
Kwangshin Oh
 
CS5261 Group 8 Presentation - US Mobile Industry
Kwangshin Oh
 
Jini Network Technology
Kwangshin Oh
 
Object-Oriented Programming Concepts
Kwangshin Oh
 

Recently uploaded (20)

PDF
Alur Perkembangan Software dan Jaringan Komputer
ssuser754303
 
PPTX
declaration of Variables and constants.pptx
meemee7378
 
PDF
Writing Maintainable Playwright Tests with Ease
Shubham Joshi
 
PDF
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
PPTX
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
 
PPTX
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
PDF
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 
PPTX
CV-Project_2024 version 01222222222.pptx
MohammadSiddiqui70
 
PDF
Why Edge Computing Matters in Mobile Application Tech.pdf
IMG Global Infotech
 
PDF
Laboratory Workflows Digitalized and live in 90 days with Scifeon´s SAPPA P...
info969686
 
PPTX
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
PPTX
Avast Premium Security crack 25.5.6162 + License Key 2025
HyperPc soft
 
PDF
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
 
PPTX
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
 
PDF
AWS Consulting Services: Empowering Digital Transformation with Nlineaxis
Nlineaxis IT Solutions Pvt Ltd
 
PPT
Information Communication Technology Concepts
LOIDAALMAZAN3
 
PPTX
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
 
PDF
WholeClear Split vCard Software for Split large vCard file
markwillsonmw004
 
PDF
Rewards and Recognition (2).pdf
ethan Talor
 
PDF
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
 
Alur Perkembangan Software dan Jaringan Komputer
ssuser754303
 
declaration of Variables and constants.pptx
meemee7378
 
Writing Maintainable Playwright Tests with Ease
Shubham Joshi
 
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
 
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 
CV-Project_2024 version 01222222222.pptx
MohammadSiddiqui70
 
Why Edge Computing Matters in Mobile Application Tech.pdf
IMG Global Infotech
 
Laboratory Workflows Digitalized and live in 90 days with Scifeon´s SAPPA P...
info969686
 
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
Avast Premium Security crack 25.5.6162 + License Key 2025
HyperPc soft
 
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
 
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
 
AWS Consulting Services: Empowering Digital Transformation with Nlineaxis
Nlineaxis IT Solutions Pvt Ltd
 
Information Communication Technology Concepts
LOIDAALMAZAN3
 
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
 
WholeClear Split vCard Software for Split large vCard file
markwillsonmw004
 
Rewards and Recognition (2).pdf
ethan Talor
 
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
 

Ruby Programming Language - Introduction

  • 1. Ruby Programming Language Introduction 28 Jun 2015 Kwangshin Oh [email protected] http://kwangshin.pe.kr
  • 2. Seven Languages in Seven Weeks A Pragmatic Guide to Learning Programming Languages By Bruce A. Tate
  • 3. Why New Programming Language? “Learning a new programming language will show you new ways of thinking, and new approaches to problem solving that will help you be a better programmer in any language.” - Pragmatic Bookshelf “Ultimately, programming is about understanding, and understanding is about ideas. So, exposure to new ideas is essential to a deeper understanding of what programming is all about.” - Foreword By Joe Armstrong, creator of Erlang
  • 4. Agenda  Ruby is…  History & Why?  With a Spoonful of Sugar  So, Ruby is…  Ruby: Interpreted Language  Ruby: Interpreted Language – Example  Compare: Compiled Language - Java  Ruby: Object-Oriented Language  Ruby: Pure Object-Oriented Language  Ruby: Dynamically Typed Language  What is Duck Typing?  Ruby: Duck Typing Code Example  Download & Installation  Ruby Code  Reference
  • 5. Ruby is…  Programming Language! Dynamic Open Source  Focus on… Simplicity Productivity  Has an elegant syntax Natural to read Easy to write Image Source: Ruby Programming Language
  • 6. History & Why?  Ruby’s Creator Yukihiro “Matz” Matsumoto  Created in about 1993  Motivation The primary motivation was to amuse himself! Just a hobby at the beginning New object-oriented language that combines characteristics from Lisp, Smalltalk and Perl To enhance programmers’ productivity “Ruby is simple in appearance, but is very complex inside, just like our human body.” - Matz, speaking on the Ruby-Talk mailing list, May 12th, 2000. Image Source: Ruby Everywhere
  • 7. With a Spoonful of Sugar  Ruby with more syntactic sugar Makes code easier to read and write  Focus on the efficiency of the programmers “A spoonful of sugar makes the medicine go down.” Mary Poppins Image Source: Disney Wiki – A Spoonful of Sugar
  • 8. So, Ruby is…  Interpreted Language Ruby code is executed by an interpreter  Object-Oriented Language Encapsulation Inheritance Polymorphism  Dynamically Typed Language Types are bound at execution time Image Source: Skillcrush - Ruby
  • 9. Interactive Console Ruby File (*.rb) Ruby: Interpreted Language Image Source: http://www.iconsdb.com, http://dryicons.com and http://findicons.com Ruby Interpreter
  • 10. Interactive Console Ruby File (Ha.rb) Ruby: Interpreted Language - Example D:Ruby22bin>type Ha.rb 3.Times do print “Ha “ end D:Ruby22bin>ruby Ha.rb Ha Ha Ha D:Ruby22bin> D:Ruby22bin>ruby 3.Times do print “Ha “ end ^D Ha Ha Ha D:Ruby22bin>
  • 11. Compare: Compiled Language - Java Java Source File (*.java) Java Compiler Java Class File (*.class) JRE (Java Runtime Environment)
  • 12. Ruby: Object-Oriented Language  Encapsulation [State & Behavior] : Packaged together  Inheritance [Class Tree] : Object types are organized  Polymorphism [Many Forms] : Objects can be shown Image Source: What Is an Object? Image Source: What Is Inheritance?Image Source: Object-Oriented Concepts
  • 13. Ruby: Pure Object-Oriented Language  Ruby Programming Language Everything is an object!  Compare: Java Programming Language Primitive types (int, char, ……) are not objects! D:Ruby22bin>irb irb(main):001:0> 4 => 4 irb(main):002:0> 4.class => Fixnum irb(main):003:0> 4 + 4 => 8 irb(main):004:0> 4.methods => [:to_s, :inspect, :- @, :+, ∙∙∙∙∙∙, :__id__] irb(main):005:0>
  • 14. Ruby: Dynamically Typed Language Types are bound at execution time Flexibility Execution Safety  Types are bound at compile time  Flexibility  Execution Safety Dynamically Typed Statically Typed Java
  • 15. What is Duck Typing? Quacks like a duck Swims like a duck Walks like a duck Call it a duck “When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck.” - James Whitcomb Riley Image Source: https://www.iconfinder.com and http://www.vectors4all.net/
  • 16. Ruby: Duck Typing Code Example D:Ruby22bin>irb irb(main):001:0> i = 0 => 0 irb(main):002:0> a = ['100', 100.0] => ["100", 100.0] irb(main):003:0> while i < 2 irb(main):004:1> puts a[i].to_i irb(main):005:1> i = i + 1 irb(main):006:1> end 100 100 => nil irb(main):007:0> We consider this to_i method as quack! Duck typing doesn’t care what the underlying type might be (whether string or float). string float
  • 17. Download & Installation  Current Stable Version  Ruby 2.2.2 (As of 28 Jun 2015)  Windows  RubyInstaller - http://rubyinstaller.org/downloads/  OS X  Homebrew - http://brew.sh/  Debian GNU/Linux and Ubuntu  apt – command : $ sudo apt-get install ruby-full  CentOS, Fedora, and RHEL  yum – command :$ sudo yum install ruby
  • 18. Ruby: Sample Code D:Ruby22bin>ruby properties = ['object oriented', 'duck typed', 'productive', 'fun'] properties.each {|property| puts "Ruby is #{property}."} ^D Ruby is object oriented. Ruby is duck typed. Ruby is productive. Ruby is fun. D:Ruby22bin>
  • 19. Ruby Code: Hello World! D:Ruby22bin>irb irb(main):001:0> puts 'Hello World!' Hello World! => nil irb(main):002:0> language = 'Ruby' => "Ruby" irb(main):003:0> puts "Hello, #{language}" Hello, Ruby => nil irb(main):004:0> language = 'my Ruby' => "my Ruby" irb(main):005:0> puts "Hello, #{language}" Hello, my Ruby => nil irb(main):006:0> Ruby’s Interactive Console <One Quote String> Interpreted Literally <Two Quotes String> String Evaluation
  • 20. Ruby Code: Comparison Operators D:Ruby22bin>irb irb(main):001:0> x = 4 => 4 irb(main):002:0> x < 5 => true irb(main):003:0> x > 4 => false irb(main):004:0> false.class => FalseClass irb(main):005:0> true.class => TrueClass irb(main):006:0> puts 'X value is equal to 4.' if x == 4 X value is equal to 4. => nil irb(main):007:0> Everything is an object in Ruby!
  • 21. Ruby Code: Loops – until & while D:Ruby22bin>irb irb(main):001:0> x = 5 => 5 irb(main):002:0> x = x - 1 until x == 1 => nil irb(main):003:0> x => 1 irb(main):004:0> while x < 5 irb(main):005:1> x = x + 1 irb(main):006:1> puts x irb(main):007:1> end 2 3 4 5 => nil
  • 22. Ruby Code: Expressions - true & false D:Ruby22bin>irb irb(main):001:0> puts '1 is true in Ruby' if 1 1 is true in Ruby => nil irb(main):002:0> puts 'String is true in Ruby' if 'Kwangshin Oh' (irb):2: warning: string literal in condition String is true in Ruby => nil irb(main):003:0> puts '0 is also true in Ruby' if 0 0 is also true in Ruby => nil irb(main):004:0> puts 'The false is false in Ruby' if false => nil irb(main):005:0> puts 'The nil is false in Ruby' if nil => nil irb(main):006:0> Everything ( but nil and false ) evaluate to true!
  • 23. Reference  Seven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Language by Bruce A. Tate  https://pragprog.com/book/btlang/seven-languages-in-seven-weeks  Ruby Programming Language  https://www.ruby-lang.org/  Ruby-Talk mailing list, May 12th, 2000  http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/2773  Disney Wiki – A Spoonful of Sugar  http://disney.wikia.com/wiki/A_Spoonful_of_Sugar  Matzにっき (Matz Diary)  http://www.rubyist.net/~matz/  The Java™ Tutorials - Object-Oriented Programming Concepts  https://docs.oracle.com/javase/tutorial/java/concepts/index.html  Duck typing  https://en.wikipedia.org/wiki/Duck_typing