SlideShare uma empresa Scribd logo
1 de 43
Baixar para ler offline
Ruby
• Japan,	
  1993

• Perl,	
  Smalltalk,	
  Lisp

• Readability,	
  writability
• English	
  language,	
  1999

• Windows,	
  Linux,	
  Mac	
  OS	
  X

  • Included	
  with	
  Apple	
  developer	
  tools
• “Everything	
  is	
  an	
  object.”
                      •   Except	
  for	
  primiNves.	
  But	
  you	
  can	
  box	
  those.
                      •   Arrays	
  are	
  special.
                      •   Classes	
  are	
  a	
  liQle	
  special,	
  too.




• “Everything	
  is	
  an	
  object.”
 •   Period.
Everything	
  is	
  an	
  object

1.class           # => Fixnum
'a'.class         # => String
:z.class          # => Symbol

class Foo
end

Foo.class         # => Class
Foo.new.class     # => Foo
Dynamically	
  typed
def do_stuff(thing)
  thing.do_the_stuff
end

class TheThing
  def do_the_stuff
    puts "Stuff was done!"
  end
end

do_stuff(TheThing.new)
Dynamically	
  typed
t = TheThing.new
t.respond_to? :do_the_stuff   # => true

def do_stuff(thing)
  if thing.respond_to? :do_the_stuff
    thing.do_the_stuff
  else
    raise "What on earth is this?"
  end
end
The	
  language
Strings	
  &	
  variables



name = 'World'   # => "World"

"Hello, #{name}" # => "Hello, World"

'Hello, #{name}' # => "Hello, #{name}"
Every	
  expression	
  has	
  a	
  value


def say_it_isnt_so(really = false)
  if really
    "All's fine!"
  else
    "All your base are belong to us."
  end
end

say_it_isnt_so        # => "All your base
                            are belong to us."
say_it_isnt_so true   # => "All's fine!"
Return



def do_complicated_stuff(take_shortcut)
  if take_shortcut
    return 42
  end
  do_really_complicated_stuff
end
Numbers

1   + 1           #   =>   2
1   + 1.1         #   =>   2.1
6   * 7           #   =>   42
6   ** 7          #   =>   279936

Math.sqrt(65536) # => 256.0

1.class           # => Fixnum
(2 ** 42).class   # => Fixnum
(2 ** 64).class   # => Bignum

1.1.class         # => Float
Arrays


Array.new      # => []
Array.new(3)   # => [nil, nil, nil]
[]             # => []

a = [1,2,3]    #   =>   [1, 2, 3]
a[0] = 'one'   #   =>   "one"
a              #   =>   ["one", 2, 3]
a[-1]          #   =>   3
a[1..2]        #   =>   [2, 3]
Arrays
a = [1,2,3]      # => [1, 2, 3]




a.push 4         # => ["one", 2, 3, 4]
a.pop            # => 4
a                # => ["one", 2, 3]




[1,2,3] | [2, 4] # => [1, 2, 3, 4]
[1,2,3] & [2, 4] # => [2]
Hashes

Hash.new              # => {}
{}                    # => {}

h = {1 => "one", 2 => "two"}
h[1]                 # => "one"
h["1"]               # => nil

h[:one] = "einz"     # => "einz"
h[:one]              # => "einz"

h.keys               # => [1, 2, :one]
h.values             # => ["one", "two", "einz"]
Fun	
  with	
  arrays	
  &	
  hashes


def do_stuff(options = {})
  puts options[:hello] if options.include?(:hello)
end

do_stuff
# => nil
do_stuff :hello => "hi"
# hi
# => nil
Fun	
  with	
  arrays	
  &	
  hashes

[1,2,3,5,7].select {|x| x.even?}
# => [2]

[1,2,3,5,7].inject(1) { |x, n| n * x}
# => 210

[1,2,3,5,7].map { |n| n * n }
# => [1, 4, 9, 25, 49]

{1 => "one", 2 => "two"}.map { |k,v| v }
# => ["one", "two"]
Control	
  structures

if condition
  # ...
elsif other_condition
  # ...
end

unless condition
  # ...
end

while
  # ...
end
Control	
  structures



case   (1024)
when   42 then puts "my favorite number"
when   2 then puts "my second favorite number"
when   1024, 2048 then puts "fair enough"
else   "this number sucks"
end
Control	
  structures


puts "How are you gentlemen!!" if role.cats?




puts "mommy!" while reaction_from_mommy.nil?
class Pet                      Classes
  attr_accessor :name

  def initialize(name)
    @name = name
  end

  def sit!
    puts "Wuff"
  end
end

fido = Pet.new("fido") # => #<Pet:0x10116e908
                              @name="fido">
fido.name              # => "fido"
fido.sit!              # => "Wuff"
Classes

class Cat < Pet
  def sit!
    if rand(10) > 8 # decide our mood
      super
    else
      puts "No way!"
    end
  end
end

mimi = Cat.new("mimi") # => #<Cat:0x101131d00
                              @name="mimi">
mimi.sit!              # => "No way!"
Classes
class Cat
  def self.purr
    puts "Huh, what? I'm the class!"
  end

  def purr
    puts "prrrrrrr"
  end
end

Cat.purr
# "Huh, what? I'm the class!"
Cat.new("mimi").purr
# prrrrrrr
Classes


class Fixnum
  def even?
    return false if eql? 2
    super
  end
end

2.even? # => false
4.even? # => true
Modules
       module ThingsDoer
         def do_one_thing
           puts "doing one thing"
         end
       end

       ThingsDoer::do_one_thing
       # "doing one thing"


# Modules can be used to group methods,
classes or other modules
Modules


class Pet
  include ThingsDoer
end

# we had a Pet instance of fido

fido.do_one_thing
# "doing one thing"
Naming	
  convenDons



CamelCased       # Classes, modules
with_underscores # methods, local variables

@instance_variable
@@class_variable
$GLOBAL_VARIABLE
Code	
  blocks
[1,2,3,5,7].select {|x| x.even?}
# => [2]

def do_random_nr_of_times &block
  nr = rand(10)
  for i in 1..nr
    yield
  end
end

do_random_nr_of_times { puts "bla" }
# bla
# bla
# bla
# => 1..3
Code	
  blocks


def run
  value = "bla"
  do_random_nr_of_times { puts value }
end
run
# bla
# bla
# => 1..2
Code	
  blocks
the_time = Time.now
# Sun Nov 29 20:15:47 0100 2009
the_time
# Sun Nov 29 20:15:47 0100 2009
the_time
# Sun Nov 29 20:15:47 0100 2009

>> the_time = lambda { Time.now }
# => #<Proc:0x0000000100567178@(irb):463>
the_time.call
# Sun Nov 29 20:18:16 0100 2009
the_time.call
# Sun Nov 29 20:18:20 0100 2009
OpDonal	
  language	
  elements

def my_method(data, options = {})
  # ...
end

# Full signature
my_method("bla", {:option => 'value', :two => 2})
# The last parameter a hash? implicit.
my_method("bla", :option => 'value', :two => 2)
# Parentheses are optional
my_method "bla", :option => 'value', :two => 2

# As long as its unambiguous, it's OK
Regular	
  expressions

s = "Ruby rules"
# => "Ruby rules"
s =~ /rules/
# => 5
s.gsub(/es/, "ez")
# => "Ruby rulez"
s.gsub(/[aeiou]/, "*")
# => "R*by r*l*s"
m = s.match(/([aeiou][^aeiou])/)
# => #<MatchData "ub" 1:"ub">
m[0]
# => "ub"
ExcepDons
begin
  raise "Someone set us up the bomb."
rescue => e
  puts e.inspect
end
# <RuntimeError: Someone set us up the bomb.>

begin
  raise StandardError.new("For great justice.")
rescue StandardError
  puts "standard"
rescue RuntimeError
  puts "runtime"
end
# standard
What’s	
  more?


• No	
  threading	
  (at	
  least,	
  by	
  default)
• Only	
  false	
  and	
  nil	
  are	
  not	
  true
       def my_method(my_object)
         puts my_object && my_object.to_s
       end
       my_method(1)    # => 1
       my_method(nil) # => nil

       h[:bla] ||= "bla"
Tools
irb
Textmate
What	
  haven’t	
  I	
  talked	
  about?



• TesNng
 • RSpec
• DocumentaNon
 • RDoc
What	
  haven’t	
  I	
  talked	
  about?


• Gems
 • Like	
  ‘apt’	
  for	
  ruby
• Deployment
 • SVN
 • Capistrano
What	
  haven’t	
  I	
  talked	
  about?
class BlogPost < ActiveRecord::Base
  belongs_to :user
  has_many :comments

  validates_presence_of :user_id
  validates_associated :user

  validates_length_of :title, :within => 10..100
  validates_length_of :body, :within => 100..5000
end

BlogPost.new(:title -> "My first blog", :body => "is
way too short.")
What	
  haven’t	
  I	
  talked	
  about?



• Ruby	
  on	
  Rails
  • Web	
  framework
  • Strict	
  MVC	
  separaNon
  • Handles	
  persistence
                                 http://pragprog.com/
                                           titles/rails2
module Ruby
  include(DynamicLanguage)
  include(ObjectOriented)
  include(DuckTyping)

  def ruby
    @everything_is_an_object = true
  end

  def language
    {"hashes" => :awesome, "array" => :awesome}
    value = 'supported'
    "String variable substibution is #{value}"
  end

  def tools
    {:editor => 'Textmate',
      :runtime => 'included in OS X'}
  end
end
thank_audience
  :speaker => 'Angelo vd Sijpt',
  :greeting => 'You were awesome!',
  :find_more_at ['ruby-lang.org',
                 'rubyists.eu']

Mais conteúdo relacionado

Último

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
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
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
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...Miguel Araújo
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
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 WorkerThousandEyes
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Último (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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)
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
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...
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Destaque

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 

Destaque (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

Ruby Intro

  • 2. • Japan,  1993 • Perl,  Smalltalk,  Lisp • Readability,  writability
  • 3. • English  language,  1999 • Windows,  Linux,  Mac  OS  X • Included  with  Apple  developer  tools
  • 4. • “Everything  is  an  object.” • Except  for  primiNves.  But  you  can  box  those. • Arrays  are  special. • Classes  are  a  liQle  special,  too. • “Everything  is  an  object.” • Period.
  • 5. Everything  is  an  object 1.class # => Fixnum 'a'.class # => String :z.class # => Symbol class Foo end Foo.class # => Class Foo.new.class # => Foo
  • 6. Dynamically  typed def do_stuff(thing) thing.do_the_stuff end class TheThing def do_the_stuff puts "Stuff was done!" end end do_stuff(TheThing.new)
  • 7. Dynamically  typed t = TheThing.new t.respond_to? :do_the_stuff # => true def do_stuff(thing) if thing.respond_to? :do_the_stuff thing.do_the_stuff else raise "What on earth is this?" end end
  • 9. Strings  &  variables name = 'World' # => "World" "Hello, #{name}" # => "Hello, World" 'Hello, #{name}' # => "Hello, #{name}"
  • 10. Every  expression  has  a  value def say_it_isnt_so(really = false) if really "All's fine!" else "All your base are belong to us." end end say_it_isnt_so # => "All your base are belong to us." say_it_isnt_so true # => "All's fine!"
  • 11. Return def do_complicated_stuff(take_shortcut) if take_shortcut return 42 end do_really_complicated_stuff end
  • 12. Numbers 1 + 1 # => 2 1 + 1.1 # => 2.1 6 * 7 # => 42 6 ** 7 # => 279936 Math.sqrt(65536) # => 256.0 1.class # => Fixnum (2 ** 42).class # => Fixnum (2 ** 64).class # => Bignum 1.1.class # => Float
  • 13. Arrays Array.new # => [] Array.new(3) # => [nil, nil, nil] [] # => [] a = [1,2,3] # => [1, 2, 3] a[0] = 'one' # => "one" a # => ["one", 2, 3] a[-1] # => 3 a[1..2] # => [2, 3]
  • 14. Arrays a = [1,2,3] # => [1, 2, 3] a.push 4 # => ["one", 2, 3, 4] a.pop # => 4 a # => ["one", 2, 3] [1,2,3] | [2, 4] # => [1, 2, 3, 4] [1,2,3] & [2, 4] # => [2]
  • 15. Hashes Hash.new # => {} {} # => {} h = {1 => "one", 2 => "two"} h[1] # => "one" h["1"] # => nil h[:one] = "einz" # => "einz" h[:one] # => "einz" h.keys # => [1, 2, :one] h.values # => ["one", "two", "einz"]
  • 16. Fun  with  arrays  &  hashes def do_stuff(options = {}) puts options[:hello] if options.include?(:hello) end do_stuff # => nil do_stuff :hello => "hi" # hi # => nil
  • 17. Fun  with  arrays  &  hashes [1,2,3,5,7].select {|x| x.even?} # => [2] [1,2,3,5,7].inject(1) { |x, n| n * x} # => 210 [1,2,3,5,7].map { |n| n * n } # => [1, 4, 9, 25, 49] {1 => "one", 2 => "two"}.map { |k,v| v } # => ["one", "two"]
  • 18. Control  structures if condition # ... elsif other_condition # ... end unless condition # ... end while # ... end
  • 19. Control  structures case (1024) when 42 then puts "my favorite number" when 2 then puts "my second favorite number" when 1024, 2048 then puts "fair enough" else "this number sucks" end
  • 20. Control  structures puts "How are you gentlemen!!" if role.cats? puts "mommy!" while reaction_from_mommy.nil?
  • 21. class Pet Classes attr_accessor :name def initialize(name) @name = name end def sit! puts "Wuff" end end fido = Pet.new("fido") # => #<Pet:0x10116e908 @name="fido"> fido.name # => "fido" fido.sit! # => "Wuff"
  • 22. Classes class Cat < Pet def sit! if rand(10) > 8 # decide our mood super else puts "No way!" end end end mimi = Cat.new("mimi") # => #<Cat:0x101131d00 @name="mimi"> mimi.sit! # => "No way!"
  • 23. Classes class Cat def self.purr puts "Huh, what? I'm the class!" end def purr puts "prrrrrrr" end end Cat.purr # "Huh, what? I'm the class!" Cat.new("mimi").purr # prrrrrrr
  • 24. Classes class Fixnum def even? return false if eql? 2 super end end 2.even? # => false 4.even? # => true
  • 25. Modules module ThingsDoer def do_one_thing puts "doing one thing" end end ThingsDoer::do_one_thing # "doing one thing" # Modules can be used to group methods, classes or other modules
  • 26. Modules class Pet include ThingsDoer end # we had a Pet instance of fido fido.do_one_thing # "doing one thing"
  • 27. Naming  convenDons CamelCased # Classes, modules with_underscores # methods, local variables @instance_variable @@class_variable $GLOBAL_VARIABLE
  • 28. Code  blocks [1,2,3,5,7].select {|x| x.even?} # => [2] def do_random_nr_of_times &block nr = rand(10) for i in 1..nr yield end end do_random_nr_of_times { puts "bla" } # bla # bla # bla # => 1..3
  • 29. Code  blocks def run value = "bla" do_random_nr_of_times { puts value } end run # bla # bla # => 1..2
  • 30. Code  blocks the_time = Time.now # Sun Nov 29 20:15:47 0100 2009 the_time # Sun Nov 29 20:15:47 0100 2009 the_time # Sun Nov 29 20:15:47 0100 2009 >> the_time = lambda { Time.now } # => #<Proc:0x0000000100567178@(irb):463> the_time.call # Sun Nov 29 20:18:16 0100 2009 the_time.call # Sun Nov 29 20:18:20 0100 2009
  • 31. OpDonal  language  elements def my_method(data, options = {}) # ... end # Full signature my_method("bla", {:option => 'value', :two => 2}) # The last parameter a hash? implicit. my_method("bla", :option => 'value', :two => 2) # Parentheses are optional my_method "bla", :option => 'value', :two => 2 # As long as its unambiguous, it's OK
  • 32. Regular  expressions s = "Ruby rules" # => "Ruby rules" s =~ /rules/ # => 5 s.gsub(/es/, "ez") # => "Ruby rulez" s.gsub(/[aeiou]/, "*") # => "R*by r*l*s" m = s.match(/([aeiou][^aeiou])/) # => #<MatchData "ub" 1:"ub"> m[0] # => "ub"
  • 33. ExcepDons begin raise "Someone set us up the bomb." rescue => e puts e.inspect end # <RuntimeError: Someone set us up the bomb.> begin raise StandardError.new("For great justice.") rescue StandardError puts "standard" rescue RuntimeError puts "runtime" end # standard
  • 34. What’s  more? • No  threading  (at  least,  by  default) • Only  false  and  nil  are  not  true def my_method(my_object) puts my_object && my_object.to_s end my_method(1) # => 1 my_method(nil) # => nil h[:bla] ||= "bla"
  • 35. Tools
  • 36. irb
  • 38. What  haven’t  I  talked  about? • TesNng • RSpec • DocumentaNon • RDoc
  • 39. What  haven’t  I  talked  about? • Gems • Like  ‘apt’  for  ruby • Deployment • SVN • Capistrano
  • 40. What  haven’t  I  talked  about? class BlogPost < ActiveRecord::Base belongs_to :user has_many :comments validates_presence_of :user_id validates_associated :user validates_length_of :title, :within => 10..100 validates_length_of :body, :within => 100..5000 end BlogPost.new(:title -> "My first blog", :body => "is way too short.")
  • 41. What  haven’t  I  talked  about? • Ruby  on  Rails • Web  framework • Strict  MVC  separaNon • Handles  persistence http://pragprog.com/ titles/rails2
  • 42. module Ruby include(DynamicLanguage) include(ObjectOriented) include(DuckTyping) def ruby @everything_is_an_object = true end def language {"hashes" => :awesome, "array" => :awesome} value = 'supported' "String variable substibution is #{value}" end def tools {:editor => 'Textmate', :runtime => 'included in OS X'} end end
  • 43. thank_audience :speaker => 'Angelo vd Sijpt', :greeting => 'You were awesome!', :find_more_at ['ruby-lang.org', 'rubyists.eu']

Notas do Editor

  1. I have been doing Ruby on Rails for about six weeks now; time for a quick introduction! This is not intended as a be-all-and-end-all presentation; I point out the things I find interesting or surprising. Image: http://shakti.trincoll.edu/~dmerrick/images/ruby.png
  2. Image: http://ifup.org/images/duke.gif
  3. Image: http://ifup.org/images/duke.gif
  4. Image: http://ifup.org/images/duke.gif
  5. Image: http://ifup.org/images/duke.gif
  6. Image: http://ifup.org/images/duke.gif
  7. Image: http://ifup.org/images/duke.gif
  8. Image: http://ifup.org/images/duke.gif
  9. Image: http://ifup.org/images/duke.gif
  10. Symbol can be seen as a constant without any overhead. Used for indexing, as key, etc.
  11. Symbol can be seen as a constant without any overhead. Used for indexing, as key, etc.
  12. Symbol can be seen as a constant without any overhead. Used for indexing, as key, etc.
  13. Symbol can be seen as a constant without any overhead. Used for indexing, as key, etc.
  14. Symbol can be seen as a constant without any overhead. Used for indexing, as key, etc.
  15. Symbol can be seen as a constant without any overhead. Used for indexing, as key, etc.
  16. Symbol can be seen as a constant without any overhead. Used for indexing, as key, etc.
  17. Symbol can be seen as a constant without any overhead. Used for indexing, as key, etc.
  18. Ruby uses the message metaphor for methods &amp; message; you send a symbol, and the object responds Duck typing &amp; inspection
  19. Ruby uses the message metaphor for methods &amp; message; you send a symbol, and the object responds Duck typing &amp; inspection
  20. Ruby uses the message metaphor for methods &amp; message; you send a symbol, and the object responds Duck typing &amp; inspection
  21. Ruby uses the message metaphor for methods &amp; message; you send a symbol, and the object responds Duck typing &amp; inspection
  22. Ruby uses the message metaphor for methods &amp; message; you send a symbol, and the object responds Duck typing &amp; inspection
  23. Ruby uses the message metaphor for methods &amp; message; you send a symbol, and the object responds Duck typing &amp; inspection
  24. Ruby uses the message metaphor for methods &amp; message; you send a symbol, and the object responds Duck typing &amp; inspection
  25. Ruby uses the message metaphor for methods &amp; message; you send a symbol, and the object responds Duck typing &amp; inspection
  26. Ruby uses the message metaphor for methods &amp; message; you send a symbol, and the object responds Duck typing &amp; inspection
  27. Ruby uses the message metaphor for methods &amp; message; you send a symbol, and the object responds Duck typing &amp; inspection
  28. the lambda method turns a codeblock into a &amp;#x2018;real&amp;#x2019; object
  29. Greatly increases readability!
  30. Greatly increases readability!
  31. Greatly increases readability!
  32. Greatly increases readability!
  33. Greatly increases readability!
  34. Greatly increases readability!
  35. Greatly increases readability!
  36. Greatly increases readability!
  37. Greatly increases readability!
  38. Greatly increases readability!
  39. Image: http://blogs.nitobi.com/alexei/wp-content/uploads/2008/04/ruby_on_rails_logo.jpg
  40. Image: http://blogs.nitobi.com/alexei/wp-content/uploads/2008/04/ruby_on_rails_logo.jpg