SlideShare una empresa de Scribd logo
1 de 14
Descargar para leer sin conexión
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...?

Más contenido relacionado

Destacado

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
 

Destacado (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
 

Similar a 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
 

Similar a 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 程式語言綜覽簡介
 

Último

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Último (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

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).