SlideShare una empresa de Scribd logo
1 de 31
Making Ruby Do Things
   How to force Ruby into submission
What is Ruby?

• Ruby is a dynamic, reflective, general-
  purpose object-oriented programming
  language...
• A dynamic, open source programming
  language with a focus on simplicity and
  productivity.
class Person
  def say something
   puts something
  end
end

# Create a person object
ryan = Person.new

# Have Ryan say hello!
ryan.say 'Hello there!'
Want to play along?

    Mac Open Terminal.app
     Window Do a thing?
    Web http://tryruby.org
The Basics
Rule #1
Everything is an object
Basic Data Types and Structures


 String               "Hello World"

Integer                     100

 Range                     1..50

 Array                    [1, 2, 3]

 Hash     { :ruby => 'neat', :javascript => 'rad' }

Regexp                     /d{3}/
Strings and Integers
Strings and Integers
name = 'Ryan'
Strings and Integers
name = 'Ryan'

# Comparing numbers (in a hash, by the way)
Strings and Integers
name = 'Ryan'

# Comparing numbers (in a hash, by the way)
hours[:xbox] = 473
Strings and Integers
name = 'Ryan'

# Comparing numbers (in a hash, by the way)
hours[:xbox] = 473
hours[:worked] = 3
Strings and Integers
name = 'Ryan'

# Comparing numbers (in a hash, by the way)
hours[:xbox] = 473
hours[:worked] = 3

hours[:xbox] > hours[:worked]
Strings and Integers
name = 'Ryan'

# Comparing numbers (in a hash, by the way)
hours[:xbox] = 473
hours[:worked] = 3

hours[:xbox] > hours[:worked]
=> true
Arrays

people = [ 'Kirk', 'Andy', 'Jamie' ]

people[2]
=> 'Jamie'
Arrays

people = [ 'Kirk', 'Andy', 'Jamie' ]
              0       1      2
people[2]
=> 'Jamie'
Hashes
skillz = {
  ryan: [ 'Ruby on Rails', 'HTML5' ],
  bob: [ 'Illustrator', 'Photoshop' ]
}

skillz[:ryan][0]
=> Ruby on Rails
Ranges
beers = (2..10)

beers.each do |count|
 puts case count
  when 2..3 then "#{count} beers? No problem!"
  when 4..7 then "Approaching dangerous territory."
  when 8..10 then "Seriously?? #{count} beers?"
 end
end

=> 2 beers? No problem!
=> 3 beers? No problem!
=> Approaching dangerous territory.
=> ...
Control Structures
Control Structures
if condition
  # do something
elsif condition
  # do something
else
  # do something
end
Control Structures
if condition       case myvar
  # do something    when foo then "Hello!"
elsif condition     when baz then "Good bye"
  # do something   end
else
  # do something
end
Control Structures
if condition       case myvar
  # do something    when foo then "Hello!"
elsif condition     when baz then "Good bye"
  # do something   end
else
  # do something      while condition
end                    # do something
                      end
Classes and Methods
  A little hot object-oriented action
There are all kinds of objects
Methods


def greet(name)
 puts "Hello, #{name}!"
end
Classes

class Human
  def greet(name)
   puts "Hello, #{name}!"
  end
end
Putting it all together
    class Human
      def greet(name)
       puts "Hello, #{name}!"
      end
    end

    human = Human.new
    human.greet('Ryan')
Stop.
Demo time!
cylen.cc/F47w
Thanks!

• Ryan L. Cross
• Twitter: @slant
• Github: github.com/cylence
• The Enclave: enclavecoop.com
• ExtendedZombieSlayer2000
  cylen.cc/F4vy

Más contenido relacionado

Destacado (6)

Irma Project Profile V 2.2
Irma Project Profile V 2.2Irma Project Profile V 2.2
Irma Project Profile V 2.2
 
2007 Prediction www.Free Prosper Pack.Com Lenai Stewart (631)961 8811.Rtf
2007 Prediction www.Free Prosper Pack.Com Lenai Stewart (631)961 8811.Rtf2007 Prediction www.Free Prosper Pack.Com Lenai Stewart (631)961 8811.Rtf
2007 Prediction www.Free Prosper Pack.Com Lenai Stewart (631)961 8811.Rtf
 
D0.1 V2.0 Project Presentation
D0.1 V2.0 Project PresentationD0.1 V2.0 Project Presentation
D0.1 V2.0 Project Presentation
 
Conquering Chief Lenai Stewart
Conquering Chief Lenai StewartConquering Chief Lenai Stewart
Conquering Chief Lenai Stewart
 
LBP Update
LBP UpdateLBP Update
LBP Update
 
Evidence at Your Fingertips: Elegance Solutions for Painful Processes
Evidence at Your Fingertips:  Elegance Solutions for Painful ProcessesEvidence at Your Fingertips:  Elegance Solutions for Painful Processes
Evidence at Your Fingertips: Elegance Solutions for Painful Processes
 

Similar a Introduction to Ruby

Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手
Wen-Tien Chang
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽
Wen-Tien Chang
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介
Wen-Tien Chang
 
Joshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages TodayJoshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages Today
Refresh Events
 
Async. and Realtime Geo Applications with Node.js
Async. and Realtime Geo Applications with Node.jsAsync. and Realtime Geo Applications with Node.js
Async. and Realtime Geo Applications with Node.js
Shoaib Burq
 

Similar a Introduction to Ruby (20)

Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽
 
Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7
 
Ruby 2: some new things
Ruby 2: some new thingsRuby 2: some new things
Ruby 2: some new things
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
 
Rails by example
Rails by exampleRails by example
Rails by example
 
Test First Teaching
Test First TeachingTest First Teaching
Test First Teaching
 
Ruby
RubyRuby
Ruby
 
Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love Ruby
 
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
 
Rails console
Rails consoleRails console
Rails console
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介
 
Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010
 
Searching ORM: First Why, Then How
Searching ORM: First Why, Then HowSearching ORM: First Why, Then How
Searching ORM: First Why, Then How
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
Language supports it
Language supports itLanguage supports it
Language supports it
 
An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutes
 
Joshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages TodayJoshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages Today
 
Async. and Realtime Geo Applications with Node.js
Async. and Realtime Geo Applications with Node.jsAsync. and Realtime Geo Applications with Node.js
Async. and Realtime Geo Applications with Node.js
 
Python Novice to Ninja
Python Novice to NinjaPython Novice to Ninja
Python Novice to Ninja
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Introduction to Ruby

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n