SlideShare une entreprise Scribd logo
1  sur  29
Ruby
The Ruby Language Originally  by Yukihiro "Matz" Matsumoto “Ruby is designed for programmer productivity and fun, following the principles of good user interface design. He stresses that systems design needs to emphasize human, rather than computer, needs.” http://en.wikipedia.org/wiki/Ruby_(programming_language)#History Ruby 1.0 was released in 1996.
Ruby Language Overview Dynamically typed Interpreted Can be modified at runtime Object oriented Blocks & lambdas Nice support for Regular Expressions
Lets get started IRB: InteractiveRuBy >> 4 >> 4 + 4
Everything is an object “test”.upcase “test”.class “test”.methods
Everything evaluates to something 2 + 2 (2+2).zero?
Methods are Messages thing.do(4) thing.do 4 thing.send “do”, 4
Operators are Methods thing.do 4 thing.do(4) thing.send “do”, 4 1 + 2 1.+(2) 1.send "+", 2
Write your first Ruby class
Conditionals, Iterators & Blocks With Hashes & Arrays
Conditionals
Conditionals: if if age > 17 	puts “can vote” end if age > 17 	puts “can vote” else 	puts “attends school” end Statement Modifiers: y = 7 if x == 4 Other Syntax: if x == 4 then y = 7 end
Truth Truth: Everything is true except for: false  nil Therefore 0 is true “” is true Checking for false: if !(name == “superman”) … if not (name == “superman”) …
Unless “unless” provides us with another way of checking if a condition is false: unless superpower == nil 	status = “superhero” end
Case case superhero when “superman” 		 city = “metropolis” when “batman” 		 city = “gotham_city” else	 		city = “central_city” end
Case Refactoring city = case superhero when “superman” 		 “metropolis” when “batman” 		 “gotham_city” else	 		 “central_city” end
Iterators
Iterators: Conditional Looping “while” allows us to loop through code while a set condition is true x = 1 while x < 10 	puts x.to_s + “ iteration” x += 1 end
Creating a new array x = [1, 2, 3, 4] => [1, 2, 3, 4] x = %w(1 2 3 4)  => [“1”, “2”, “3”, “4”] chef = Array.new(3, “bork”) => [“bork”, “bork”, bork”]
Accessing Array Values a = [ "a", "b", "c", "d", "e" ]  a[0] #=> "a” a[2] #=> "c” a[6] #=> nil
Creating a Hash h = { "a" => 100, "b" => 200 } h[“a”] h = { 1 => “a”, “b” => “hello” } h[1]
Operations on Hashes: Merge h1 = { "a" => 100, "b" => 200 }  => {"a"=>100, "b"=>200} h2 = { "b" => 254, "c" => 300 } =>{"b"=>254, "c"=>300} h3 = h1.merge(h2) => {"a"=>100, "b"=>254, "c"=>300} h1 => {"a"=>100, "b"=>200} h1.merge!(h2) => {"a"=>100, "b"=>254, "c"=>300}
Operations on Hashes h = { "a" => 100, "b" => 200 }  h.delete("a”) h = { "a" => 100, "b" => 200, "c" => 300, "d" => 400 } letters = h.keys  h = { "a" => 100, "b" => 200, "c" => 300 }  numbers = h.values
Times 5.times{ puts “hello” } 99.times do |beer_num|  		puts "#{beer_num} bottles of beer” end
Each superheroes = [“catwoman”, “batman”,  “wonderwoman”] superheroes.each do | s |  puts “#{ s } save me!”  end wonderwoman save me! batman save me! catwoman save me!
Blocks
Blocks def dos_veces     yield     yield end dos_veces { puts "Hola” } Hola Hola Yield executes the block This is a Block! {
Yield with Parameters def bands yield(“abba”, “who”) end bands do |x,y| puts x,y  end abba who Yield sends its parameters as arguments to the block yield(“abba”, ”who”) sends “abba” and “who” to |x, y| x is set to “abba” y is set to “who”
Mr. Neighborly's Humble Little Ruby BookJeremy McAnally The Well-Grounded RubyistCovering Ruby 1.9David A. Black Ruby Koansa walk along the path to enlightenmenthttp://github.com/edgecase/ruby_koans

Contenu connexe

Similaire à Intro To Ruby

A Toda Maquina Con Ruby on Rails
A Toda Maquina Con Ruby on RailsA Toda Maquina Con Ruby on Rails
A Toda Maquina Con Ruby on RailsRafael García
 
TechDays - IronRuby
TechDays - IronRubyTechDays - IronRuby
TechDays - IronRubyBen Hall
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Guillaume Laforge
 
Pwning Your Phone with Adhearsion and Asterisk
Pwning Your Phone with Adhearsion and AsteriskPwning Your Phone with Adhearsion and Asterisk
Pwning Your Phone with Adhearsion and Asteriskjicksta
 
루비가 얼랭에 빠진 날
루비가 얼랭에 빠진 날루비가 얼랭에 빠진 날
루비가 얼랭에 빠진 날Sukjoon Kim
 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Henry S
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In PythonMarwan Osman
 
Zendcon 2007 Features
Zendcon 2007 FeaturesZendcon 2007 Features
Zendcon 2007 Featuresfivespeed5
 
Why Python by Marilyn Davis, Marakana
Why Python by Marilyn Davis, MarakanaWhy Python by Marilyn Davis, Marakana
Why Python by Marilyn Davis, MarakanaMarko Gargenta
 
Python scripting kick off
Python scripting kick offPython scripting kick off
Python scripting kick offAndrea Gangemi
 
Impacta - Show Day de Rails
Impacta - Show Day de RailsImpacta - Show Day de Rails
Impacta - Show Day de RailsFabio Akita
 
Lean & Mean Tokyo Cabinet Recipes (with Lua) - FutureRuby '09
Lean & Mean Tokyo Cabinet Recipes (with Lua) - FutureRuby '09Lean & Mean Tokyo Cabinet Recipes (with Lua) - FutureRuby '09
Lean & Mean Tokyo Cabinet Recipes (with Lua) - FutureRuby '09Ilya Grigorik
 
Introduction To Groovy 2005
Introduction To Groovy 2005Introduction To Groovy 2005
Introduction To Groovy 2005Tugdual Grall
 
Ruby for Java Developers
Ruby for Java DevelopersRuby for Java Developers
Ruby for Java DevelopersRobert Reiz
 
Hack in the Box Keynote 2006
Hack in the Box Keynote 2006Hack in the Box Keynote 2006
Hack in the Box Keynote 2006Mark Curphey
 
Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go ProgrammingLin Yo-An
 
Ruby on Rails - Pengenalan kepada “permata” dalam pengaturcaraan
Ruby on Rails - Pengenalan kepada “permata” dalam pengaturcaraan  Ruby on Rails - Pengenalan kepada “permata” dalam pengaturcaraan
Ruby on Rails - Pengenalan kepada “permata” dalam pengaturcaraan edthix
 

Similaire à Intro To Ruby (20)

A Toda Maquina Con Ruby on Rails
A Toda Maquina Con Ruby on RailsA Toda Maquina Con Ruby on Rails
A Toda Maquina Con Ruby on Rails
 
TechDays - IronRuby
TechDays - IronRubyTechDays - IronRuby
TechDays - IronRuby
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
Pwning Your Phone with Adhearsion and Asterisk
Pwning Your Phone with Adhearsion and AsteriskPwning Your Phone with Adhearsion and Asterisk
Pwning Your Phone with Adhearsion and Asterisk
 
루비가 얼랭에 빠진 날
루비가 얼랭에 빠진 날루비가 얼랭에 빠진 날
루비가 얼랭에 빠진 날
 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In Python
 
Zendcon 2007 Features
Zendcon 2007 FeaturesZendcon 2007 Features
Zendcon 2007 Features
 
Why Python by Marilyn Davis, Marakana
Why Python by Marilyn Davis, MarakanaWhy Python by Marilyn Davis, Marakana
Why Python by Marilyn Davis, Marakana
 
Happy Coding with Ruby on Rails
Happy Coding with Ruby on RailsHappy Coding with Ruby on Rails
Happy Coding with Ruby on Rails
 
Python scripting kick off
Python scripting kick offPython scripting kick off
Python scripting kick off
 
Impacta - Show Day de Rails
Impacta - Show Day de RailsImpacta - Show Day de Rails
Impacta - Show Day de Rails
 
Lean & Mean Tokyo Cabinet Recipes (with Lua) - FutureRuby '09
Lean & Mean Tokyo Cabinet Recipes (with Lua) - FutureRuby '09Lean & Mean Tokyo Cabinet Recipes (with Lua) - FutureRuby '09
Lean & Mean Tokyo Cabinet Recipes (with Lua) - FutureRuby '09
 
Introduction To Groovy 2005
Introduction To Groovy 2005Introduction To Groovy 2005
Introduction To Groovy 2005
 
Ruby for Java Developers
Ruby for Java DevelopersRuby for Java Developers
Ruby for Java Developers
 
Hack in the Box Keynote 2006
Hack in the Box Keynote 2006Hack in the Box Keynote 2006
Hack in the Box Keynote 2006
 
Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go Programming
 
Ruby on Rails - Pengenalan kepada “permata” dalam pengaturcaraan
Ruby on Rails - Pengenalan kepada “permata” dalam pengaturcaraan  Ruby on Rails - Pengenalan kepada “permata” dalam pengaturcaraan
Ruby on Rails - Pengenalan kepada “permata” dalam pengaturcaraan
 

Plus de Sarah Allen

Internet security: a landscape of unintended consequences
Internet security: a landscape of unintended consequencesInternet security: a landscape of unintended consequences
Internet security: a landscape of unintended consequencesSarah Allen
 
RTMP: how did we get to now? (Demuxed 2019)
RTMP: how did we get to now? (Demuxed 2019)RTMP: how did we get to now? (Demuxed 2019)
RTMP: how did we get to now? (Demuxed 2019)Sarah Allen
 
Communication is a Technical Skill
Communication is a Technical SkillCommunication is a Technical Skill
Communication is a Technical SkillSarah Allen
 
Improving Federal Government Services
Improving Federal Government ServicesImproving Federal Government Services
Improving Federal Government ServicesSarah Allen
 
Transparency Wins
Transparency WinsTransparency Wins
Transparency WinsSarah Allen
 
A Short History of Computers
A Short History of ComputersA Short History of Computers
A Short History of ComputersSarah Allen
 
Making Software Fun
Making Software FunMaking Software Fun
Making Software FunSarah Allen
 
Power of Transparency
Power of TransparencyPower of Transparency
Power of TransparencySarah Allen
 
Designing for Fun
Designing for FunDesigning for Fun
Designing for FunSarah Allen
 
Ruby in the US Government for Ruby World Conference
Ruby in the US Government for Ruby World ConferenceRuby in the US Government for Ruby World Conference
Ruby in the US Government for Ruby World ConferenceSarah Allen
 
Identities of Dead People
Identities of Dead PeopleIdentities of Dead People
Identities of Dead PeopleSarah Allen
 
3 Reasons Not to Use Ruby
3 Reasons Not to Use Ruby 3 Reasons Not to Use Ruby
3 Reasons Not to Use Ruby Sarah Allen
 
Ruby Nation: Why no haz Ruby?
Ruby Nation: Why no haz Ruby?Ruby Nation: Why no haz Ruby?
Ruby Nation: Why no haz Ruby?Sarah Allen
 
Why no ruby in gov?
Why no ruby in gov?Why no ruby in gov?
Why no ruby in gov?Sarah Allen
 
People Patterns or What I learned from Toastmasters
People Patterns or What I learned from ToastmastersPeople Patterns or What I learned from Toastmasters
People Patterns or What I learned from ToastmastersSarah Allen
 
Blazing Cloud: Agile Product Development
Blazing Cloud: Agile Product DevelopmentBlazing Cloud: Agile Product Development
Blazing Cloud: Agile Product DevelopmentSarah Allen
 
Crowdsourced Transcription Landscape
Crowdsourced Transcription LandscapeCrowdsourced Transcription Landscape
Crowdsourced Transcription LandscapeSarah Allen
 
Lessons Learned Future Thoughts
Lessons Learned Future ThoughtsLessons Learned Future Thoughts
Lessons Learned Future ThoughtsSarah Allen
 
Mobile Web Video
Mobile Web VideoMobile Web Video
Mobile Web VideoSarah Allen
 

Plus de Sarah Allen (20)

Internet security: a landscape of unintended consequences
Internet security: a landscape of unintended consequencesInternet security: a landscape of unintended consequences
Internet security: a landscape of unintended consequences
 
RTMP: how did we get to now? (Demuxed 2019)
RTMP: how did we get to now? (Demuxed 2019)RTMP: how did we get to now? (Demuxed 2019)
RTMP: how did we get to now? (Demuxed 2019)
 
Communication is a Technical Skill
Communication is a Technical SkillCommunication is a Technical Skill
Communication is a Technical Skill
 
Improving Federal Government Services
Improving Federal Government ServicesImproving Federal Government Services
Improving Federal Government Services
 
Transparency Wins
Transparency WinsTransparency Wins
Transparency Wins
 
A Short History of Computers
A Short History of ComputersA Short History of Computers
A Short History of Computers
 
Making Software Fun
Making Software FunMaking Software Fun
Making Software Fun
 
Power of Transparency
Power of TransparencyPower of Transparency
Power of Transparency
 
Designing for Fun
Designing for FunDesigning for Fun
Designing for Fun
 
Ruby in the US Government for Ruby World Conference
Ruby in the US Government for Ruby World ConferenceRuby in the US Government for Ruby World Conference
Ruby in the US Government for Ruby World Conference
 
Identities of Dead People
Identities of Dead PeopleIdentities of Dead People
Identities of Dead People
 
Let's pretend
Let's pretendLet's pretend
Let's pretend
 
3 Reasons Not to Use Ruby
3 Reasons Not to Use Ruby 3 Reasons Not to Use Ruby
3 Reasons Not to Use Ruby
 
Ruby Nation: Why no haz Ruby?
Ruby Nation: Why no haz Ruby?Ruby Nation: Why no haz Ruby?
Ruby Nation: Why no haz Ruby?
 
Why no ruby in gov?
Why no ruby in gov?Why no ruby in gov?
Why no ruby in gov?
 
People Patterns or What I learned from Toastmasters
People Patterns or What I learned from ToastmastersPeople Patterns or What I learned from Toastmasters
People Patterns or What I learned from Toastmasters
 
Blazing Cloud: Agile Product Development
Blazing Cloud: Agile Product DevelopmentBlazing Cloud: Agile Product Development
Blazing Cloud: Agile Product Development
 
Crowdsourced Transcription Landscape
Crowdsourced Transcription LandscapeCrowdsourced Transcription Landscape
Crowdsourced Transcription Landscape
 
Lessons Learned Future Thoughts
Lessons Learned Future ThoughtsLessons Learned Future Thoughts
Lessons Learned Future Thoughts
 
Mobile Web Video
Mobile Web VideoMobile Web Video
Mobile Web Video
 

Dernier

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.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
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
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
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
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
 
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
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
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: 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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
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
 

Dernier (20)

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.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
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
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
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
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
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
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: 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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
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)
 

Intro To Ruby

  • 2. The Ruby Language Originally by Yukihiro "Matz" Matsumoto “Ruby is designed for programmer productivity and fun, following the principles of good user interface design. He stresses that systems design needs to emphasize human, rather than computer, needs.” http://en.wikipedia.org/wiki/Ruby_(programming_language)#History Ruby 1.0 was released in 1996.
  • 3. Ruby Language Overview Dynamically typed Interpreted Can be modified at runtime Object oriented Blocks & lambdas Nice support for Regular Expressions
  • 4. Lets get started IRB: InteractiveRuBy >> 4 >> 4 + 4
  • 5. Everything is an object “test”.upcase “test”.class “test”.methods
  • 6. Everything evaluates to something 2 + 2 (2+2).zero?
  • 7. Methods are Messages thing.do(4) thing.do 4 thing.send “do”, 4
  • 8. Operators are Methods thing.do 4 thing.do(4) thing.send “do”, 4 1 + 2 1.+(2) 1.send "+", 2
  • 9. Write your first Ruby class
  • 10. Conditionals, Iterators & Blocks With Hashes & Arrays
  • 12. Conditionals: if if age > 17 puts “can vote” end if age > 17 puts “can vote” else puts “attends school” end Statement Modifiers: y = 7 if x == 4 Other Syntax: if x == 4 then y = 7 end
  • 13. Truth Truth: Everything is true except for: false nil Therefore 0 is true “” is true Checking for false: if !(name == “superman”) … if not (name == “superman”) …
  • 14. Unless “unless” provides us with another way of checking if a condition is false: unless superpower == nil status = “superhero” end
  • 15. Case case superhero when “superman” city = “metropolis” when “batman” city = “gotham_city” else city = “central_city” end
  • 16. Case Refactoring city = case superhero when “superman” “metropolis” when “batman” “gotham_city” else “central_city” end
  • 18. Iterators: Conditional Looping “while” allows us to loop through code while a set condition is true x = 1 while x < 10 puts x.to_s + “ iteration” x += 1 end
  • 19. Creating a new array x = [1, 2, 3, 4] => [1, 2, 3, 4] x = %w(1 2 3 4) => [“1”, “2”, “3”, “4”] chef = Array.new(3, “bork”) => [“bork”, “bork”, bork”]
  • 20. Accessing Array Values a = [ "a", "b", "c", "d", "e" ] a[0] #=> "a” a[2] #=> "c” a[6] #=> nil
  • 21. Creating a Hash h = { "a" => 100, "b" => 200 } h[“a”] h = { 1 => “a”, “b” => “hello” } h[1]
  • 22. Operations on Hashes: Merge h1 = { "a" => 100, "b" => 200 } => {"a"=>100, "b"=>200} h2 = { "b" => 254, "c" => 300 } =>{"b"=>254, "c"=>300} h3 = h1.merge(h2) => {"a"=>100, "b"=>254, "c"=>300} h1 => {"a"=>100, "b"=>200} h1.merge!(h2) => {"a"=>100, "b"=>254, "c"=>300}
  • 23. Operations on Hashes h = { "a" => 100, "b" => 200 } h.delete("a”) h = { "a" => 100, "b" => 200, "c" => 300, "d" => 400 } letters = h.keys h = { "a" => 100, "b" => 200, "c" => 300 } numbers = h.values
  • 24. Times 5.times{ puts “hello” } 99.times do |beer_num| puts "#{beer_num} bottles of beer” end
  • 25. Each superheroes = [“catwoman”, “batman”, “wonderwoman”] superheroes.each do | s | puts “#{ s } save me!” end wonderwoman save me! batman save me! catwoman save me!
  • 27. Blocks def dos_veces yield yield end dos_veces { puts "Hola” } Hola Hola Yield executes the block This is a Block! {
  • 28. Yield with Parameters def bands yield(“abba”, “who”) end bands do |x,y| puts x,y end abba who Yield sends its parameters as arguments to the block yield(“abba”, ”who”) sends “abba” and “who” to |x, y| x is set to “abba” y is set to “who”
  • 29. Mr. Neighborly's Humble Little Ruby BookJeremy McAnally The Well-Grounded RubyistCovering Ruby 1.9David A. Black Ruby Koansa walk along the path to enlightenmenthttp://github.com/edgecase/ruby_koans

Notes de l'éditeur

  1. Conditionals are key to being able to make decisions in a programleft looks like every other languageparentheses are optional in ruby make sure to do ==, = is an assignment, == is a conditional testExplain putsright is a little different…people in ruby don’t like to type…english readableA statement modifier lets you move control structures at the end of an expression.
  2. Unlike some languages with the 0 and empty string! Binds more tightly than than the “not” keyword so you do need parentheses for example 1, but don’t need parentheses for example 2
  3. Unless can be awkward, especially with else. Usually you’ll want to use if for conditionals with else clauses.Occasionally unless is more readable:unless something is nil
  4. Alot of the time you will be using an array when you iterate over somethingAn array is just a list of items.Every spot in the list acts like a variable and you can make each spot point to a different objectW means wordsArray is a class, needs to start with capital letter
  5. IRBif you go off the array it will be nil
  6. Does anyone know what a hash is? associative array collection of key-value pairskeys can be numbers or strings Difference from an Array
  7. merge takes the value from the second hashmerge! changes h1
  8. you would think that delete should need a bang to change the hash, but delete doesn’t exist with a bangdelete returns the value
  9. 5 is an object that is an instance of the integer classtimes is a method of the 5 objecttimes is a method on an object that is an instance of integer
  10. it does the block of code three timesit is very rare that you will see a while loop in ruby...you can do the loops we did earlier, but rubyists will mock you.
  11. What is a block? It is the ability to take a block of code, wrap it up in an object and pass it to a method. Then you can run the block of code within the method any time you want…sometimes twice! The result is kind of like sending a method to a method, except that a block isn’t bound to an object like a method is – it is an object. So what? Why use blocks?elegant syntax for iteratorsBecause there are some things that only blocks can do, like being passed to a method and being returned by a method.