SlideShare ist ein Scribd-Unternehmen logo
1 von 14
Downloaden Sie, um offline zu lesen
Introduction to Ruby
Ruby is...
●   A dynamic
●   open source
●   focus on simplicity and productivity
●   elegant syntax
Download & Install Now
    Windows
●   http://rubyforge.org/frs/download.php/47082/ruby186-2


    Linux
●   sudo apt-get install ruby irb rdoc
●   Interactive Ruby
●   Methods
●   Classes
●   Objects
●   Blocks and Looping
●   From PHP to Ruby
Interactive Ruby

irb(main):001:0>

irb(main):001:0> "Hello World"
=> "Hello World"



irb(main):002:0> puts "Hello World"
Hello World
=> nil
Module

irb(main):004:0> 3*2
=> 6

irb(main):005:0> 3**2
=> 9


irb(main):006:0> Math.sqrt(9)
=> 3.0


irb(main):007:0> a = 3 ** 2
=> 9
irb(main):008:0> b = 4 ** 2
=> 16
irb(main):009:0> Math.sqrt(a+b) => 5.0
Methods
irb(main):010:0> def h
irb(main):011:1> puts "Hello World!"
irb(main):012:1> end
=> nil

#Run the method

irb(main):013:0> h
Hello World!
=> nil
irb(main):014:0> h()
Hello World!
=> nil
Methods
irb(main):015:0> def h(name)
irb(main):016:1> puts "Hello #{name}!"
irb(main):017:1> end
=> nil
irb(main):018:0> h("Jins")
Hello Jins!
=> nil


irb(main):019:0> def h(name = "World")
irb(main):020:1> puts "Hello #{name.capitalize}!"
irb(main):021:1> end
=> nil
irb(main):022:0> h "jinson"
Hello Jinson!
=> nil
irb(main):023:0> h
Hello World!
=> nil
Classes


irb(main):024:0> class Greeter
irb(main):025:1> def initialize(name = "World")
irb(main):026:2> @name = name
irb(main):027:2> end
irb(main):028:1> def say_hi
irb(main):029:2> puts "Hi #{@name}!"
irb(main):030:2> end
irb(main):031:1> def say_bye
irb(main):032:2> puts "Bye #{@name}, come back soon."
irb(main):033:2> end
irb(main):034:1> end
=> nil
Create an Object

irb(main):035:0> g = Greeter.new("Jins")
=> #<Greeter:0x16cac @name="JIns">
irb(main):036:0> g.say_hi
Hi Jins!
=> nil
irb(main):037:0> g.say_bye
Bye Jins, come back soon.
=> nil
Cycling and Looping

@names.each do |name|
 puts "Hello #{name}!"
end



#C Code

for (i=0; i<number_of_elements; i++)
{
  do_something_with(element[i]);
}
Ruby & PHP - Similarities
●   Ruby is dynamically typed, like in PHP, so you don’t need to worry about having to
    declare variables.
●   There are classes, and you can control access to them like in PHP 5 (public, protected
    and private)
●   Some variables start with $, like in PHP (but not all)
●   There’s eval, too.
●   You can use string interpolating. Instead of doing ”$foo is a $bar”, you can do ”#{foo} is
    a #{bar}”—like in PHP, this doesn’t apply for single-quoted strings.
●   There’s heredocs
●   Ruby has exceptions, like PHP 5
●   There’s a fairly large standard library
●   Arrays and hashes work like expected, if you exchange array() for { and }: array('a' =>
    'b') becomes {'a' => 'b'}.
●   true and false behave like in PHP, but null is called nil
Ruby & PHP - Differences
●    There’s strong typing. You’ll need to call to_s, to_i etc. to convert between strings,
    integers and so on, instead of relying on the language to do it
●   Strings, numbers, arrays, hashes, etc. are objects. Instead of calling abs(-1) it’s -1.abs
●   Parentheses are optional in method calls, except to clarify which parameters go to
    which method calls
●   Variables are references.
●   There’s no abstract classes or interfaces
●   Hashes and arrays are not interchangeable
●   Only false and nil are false: 0, array() and "" are all true in conditionals.
●   Almost everything is a method call, even raise (throw in PHP).
Questions...?

Weitere ähnliche Inhalte

Andere mochten auch

The Chillr Story - Evolution of a startup from Telecom to FinTech
The Chillr Story - Evolution of a startup from Telecom to FinTechThe Chillr Story - Evolution of a startup from Telecom to FinTech
The Chillr Story - Evolution of a startup from Telecom to FinTechSony Joy
 
The MobME Story - March 2010
The MobME Story - March 2010The MobME Story - March 2010
The MobME Story - March 2010Sony Joy
 
Ppt of prannav[startup village]
Ppt of prannav[startup village]Ppt of prannav[startup village]
Ppt of prannav[startup village]suthisha
 
How to set up and Configure Kannel, A quick start
How to set up and Configure Kannel, A quick startHow to set up and Configure Kannel, A quick start
How to set up and Configure Kannel, A quick startMobME Technical
 
Web Server Load Balancer
Web Server Load BalancerWeb Server Load Balancer
Web Server Load BalancerMobME Technical
 
Startup village
Startup village Startup village
Startup village Naveen Nave
 

Andere mochten auch (10)

The Chillr Story - Evolution of a startup from Telecom to FinTech
The Chillr Story - Evolution of a startup from Telecom to FinTechThe Chillr Story - Evolution of a startup from Telecom to FinTech
The Chillr Story - Evolution of a startup from Telecom to FinTech
 
Computer Hardware
Computer HardwareComputer Hardware
Computer Hardware
 
The MobME Story - March 2010
The MobME Story - March 2010The MobME Story - March 2010
The MobME Story - March 2010
 
Introduction to JQuery
Introduction to JQueryIntroduction to JQuery
Introduction to JQuery
 
Memcache
MemcacheMemcache
Memcache
 
Ppt of prannav[startup village]
Ppt of prannav[startup village]Ppt of prannav[startup village]
Ppt of prannav[startup village]
 
How to set up and Configure Kannel, A quick start
How to set up and Configure Kannel, A quick startHow to set up and Configure Kannel, A quick start
How to set up and Configure Kannel, A quick start
 
GREEN KERALA
GREEN KERALAGREEN KERALA
GREEN KERALA
 
Web Server Load Balancer
Web Server Load BalancerWeb Server Load Balancer
Web Server Load Balancer
 
Startup village
Startup village Startup village
Startup village
 

Ähnlich wie Introduction to Ruby

Why everyone like ruby
Why everyone like rubyWhy everyone like ruby
Why everyone like rubyIvan Grishaev
 
What I Love About Ruby
What I Love About RubyWhat I Love About Ruby
What I Love About RubyKeith Bennett
 
Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technologyppparthpatel123
 
Ruby Programming Language - Introduction
Ruby Programming Language - IntroductionRuby Programming Language - Introduction
Ruby Programming Language - IntroductionKwangshin Oh
 
Minicurso Ruby e Rails
Minicurso Ruby e RailsMinicurso Ruby e Rails
Minicurso Ruby e RailsSEA Tecnologia
 
اليوم السعيد
اليوم السعيداليوم السعيد
اليوم السعيدmahersaif
 
دورتنا
دورتنادورتنا
دورتناmahersaif
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation TutorialLorna Mitchell
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Wen-Tien Chang
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Wen-Tien Chang
 

Ähnlich wie Introduction to Ruby (20)

Why everyone like ruby
Why everyone like rubyWhy everyone like ruby
Why everyone like ruby
 
What I Love About Ruby
What I Love About RubyWhat I Love About Ruby
What I Love About Ruby
 
Ruby 2.0
Ruby 2.0Ruby 2.0
Ruby 2.0
 
Rails console
Rails consoleRails console
Rails console
 
Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technology
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
 
Ruby Programming Language - Introduction
Ruby Programming Language - IntroductionRuby Programming Language - Introduction
Ruby Programming Language - Introduction
 
Minicurso Ruby e Rails
Minicurso Ruby e RailsMinicurso Ruby e Rails
Minicurso Ruby e Rails
 
I Love Ruby
I Love RubyI Love Ruby
I Love Ruby
 
a course
a coursea course
a course
 
I Love Ruby
I Love RubyI Love Ruby
I Love Ruby
 
ruby
rubyruby
ruby
 
ruby
rubyruby
ruby
 
اليوم السعيد
اليوم السعيداليوم السعيد
اليوم السعيد
 
ruby
rubyruby
ruby
 
دورتنا
دورتنادورتنا
دورتنا
 
ruby
rubyruby
ruby
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介
 

Kürzlich hochgeladen

The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Kürzlich hochgeladen (20)

The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

Introduction to Ruby

  • 2. Ruby is... ● A dynamic ● open source ● focus on simplicity and productivity ● elegant syntax
  • 3. Download & Install Now Windows ● http://rubyforge.org/frs/download.php/47082/ruby186-2 Linux ● sudo apt-get install ruby irb rdoc
  • 4. Interactive Ruby ● Methods ● Classes ● Objects ● Blocks and Looping ● From PHP to Ruby
  • 5. Interactive Ruby irb(main):001:0> irb(main):001:0> "Hello World" => "Hello World" irb(main):002:0> puts "Hello World" Hello World => nil
  • 6. Module irb(main):004:0> 3*2 => 6 irb(main):005:0> 3**2 => 9 irb(main):006:0> Math.sqrt(9) => 3.0 irb(main):007:0> a = 3 ** 2 => 9 irb(main):008:0> b = 4 ** 2 => 16 irb(main):009:0> Math.sqrt(a+b) => 5.0
  • 7. Methods irb(main):010:0> def h irb(main):011:1> puts "Hello World!" irb(main):012:1> end => nil #Run the method irb(main):013:0> h Hello World! => nil irb(main):014:0> h() Hello World! => nil
  • 8. Methods irb(main):015:0> def h(name) irb(main):016:1> puts "Hello #{name}!" irb(main):017:1> end => nil irb(main):018:0> h("Jins") Hello Jins! => nil irb(main):019:0> def h(name = "World") irb(main):020:1> puts "Hello #{name.capitalize}!" irb(main):021:1> end => nil irb(main):022:0> h "jinson" Hello Jinson! => nil irb(main):023:0> h Hello World! => nil
  • 9. Classes irb(main):024:0> class Greeter irb(main):025:1> def initialize(name = "World") irb(main):026:2> @name = name irb(main):027:2> end irb(main):028:1> def say_hi irb(main):029:2> puts "Hi #{@name}!" irb(main):030:2> end irb(main):031:1> def say_bye irb(main):032:2> puts "Bye #{@name}, come back soon." irb(main):033:2> end irb(main):034:1> end => nil
  • 10. Create an Object irb(main):035:0> g = Greeter.new("Jins") => #<Greeter:0x16cac @name="JIns"> irb(main):036:0> g.say_hi Hi Jins! => nil irb(main):037:0> g.say_bye Bye Jins, come back soon. => nil
  • 11. Cycling and Looping @names.each do |name| puts "Hello #{name}!" end #C Code for (i=0; i<number_of_elements; i++) { do_something_with(element[i]); }
  • 12. Ruby & PHP - Similarities ● Ruby is dynamically typed, like in PHP, so you don’t need to worry about having to declare variables. ● There are classes, and you can control access to them like in PHP 5 (public, protected and private) ● Some variables start with $, like in PHP (but not all) ● There’s eval, too. ● You can use string interpolating. Instead of doing ”$foo is a $bar”, you can do ”#{foo} is a #{bar}”—like in PHP, this doesn’t apply for single-quoted strings. ● There’s heredocs ● Ruby has exceptions, like PHP 5 ● There’s a fairly large standard library ● Arrays and hashes work like expected, if you exchange array() for { and }: array('a' => 'b') becomes {'a' => 'b'}. ● true and false behave like in PHP, but null is called nil
  • 13. Ruby & PHP - Differences ● There’s strong typing. You’ll need to call to_s, to_i etc. to convert between strings, integers and so on, instead of relying on the language to do it ● Strings, numbers, arrays, hashes, etc. are objects. Instead of calling abs(-1) it’s -1.abs ● Parentheses are optional in method calls, except to clarify which parameters go to which method calls ● Variables are references. ● There’s no abstract classes or interfaces ● Hashes and arrays are not interchangeable ● Only false and nil are false: 0, array() and "" are all true in conditionals. ● Almost everything is a method call, even raise (throw in PHP).