SlideShare uma empresa Scribd logo
1 de 38
Baixar para ler offline
Ruby Programming
What is Ruby ?
• Ruby – Object Oriented Programming
    Language
• Written 1995 by Yukihiro Matsumoto
• Influenced by Python,Pearl,LISP
• Easy to understand and workwith
• Simple and nice syntax
• Powerful programming capabilities

                                       #
Advantages
•   Powerful And Expressive
•   Rich Library Support
•   Rapid Development
•   Open Source
•   Flexible and Dynamic
Install Ruby
• On Fedora
    – Rpms are available
•   ruby-1.8.6.287-8.fc11.i586
•   ruby-devel
•   ruby-postgres
•   ruby-docs
•   ruby-racc
•   ruby-docs
                                 #
Types
• Command “ruby”
• The extension is .rb




                         #
Ruby Documents
• Command ri
• Example
  – ri class
  –




                            #
helloPerson.rb
•   # First ruby programme
•   def helloPerson(name)
•    result = "Hello, " + name
•    return result
•   end
•   puts helloPerson("Justin")


                                 #
Execute Programme
•   $ ruby helloPerson.rb
•   Hello, Justin
•   Nice and simple
•   Can use irb – interactive ruby shell
•   # is for comments like //



                                           #
Ruby variables
• def returnFoo
• bar = "Ramone, bring me my cup."
• return bar
• end
• puts returnFoo
•


                                     #
Kinds of Variables
•   Global variable - $ sign
•   instance variable - @ sign
•   Class Variable - @@ sign
•   Local Variable – no sign
•   Constants – Capital Letters



                                  #
Global Variable
• Available everywhere inside a
  programme
• Not use frequently




                                  #
instance variable
•   Unique inside an instance of a class
•   Truncated with instance
•   @apple = Apple.new
•   @apple.seeds = 15
•   @apple.color = "Green"
•


                                           #
•   class Course
                               Classes
•    def initialize(dept, number, name, professor)
•     @dept = dept
•     @number = number
•     @name = name
•     @professor = professor
•    end
•    def to_s
•     "Course Information: #@dept #@number - #@name [#@professor]"
•    end
•    def
•     self.find_all_students
•     ...
•    end
•   end
                                                                 #
Classes
• Initialize – is the constructor
• Def – end -> function
• Class-end -> class




                                    #
Define Object
•   class Student
•    def login_student
•      puts "login_student is running"
•    end
•   private
•    def delete_students
•    puts "delete_students is running"
•    end
•   protected
•    def encrypt_student_password
•     puts "encrypt_student_password is running"
•    end
•   end
                                                   #
Define Object
• @student = Student.new
• @student.delete_students # This will fail
• Because it is private
•




                                          #
Classes consist of methods
       and instance variables
•   class Coordinate
•         def initialize(x,y) #constructor
•             @x = x # set instance variables
•             @y = y
•         end
•         def to_s # string representation
•            "(#{@x},#{@y})"
•         end
•   end
•   point = Coordinate.new(1,5)
•   puts point
•   Will output (1,5)                           #
Inheritance
•         class AnnotatedCoordinate < Coordinate
•            def initialize(x,y,comment)
•                              super(x,y)
•                                    @comment = comment
•            end
•            def to_s
•                                    super + "[#@comment]"
•           end
•         End
•   a_point =
•   AnnotatedCoordinate.new(8,14,"Centre");
•   puts a_point
•   Out Put Is ->   (8,14)[Centre]


                                                             #
Inheritance
• Inherit a parent class
• Extend functions and variables
• Add more features to base class




                                    #
Polymorphism
• The behavior of an object that varies
  depending on the input.
•
•




                                          #
Polymorphism
•   class Person
•    # Generic features
•   end
•   class Teacher < Person
•    # A Teacher can enroll in a course for a semester as either
•    # a professor or a teaching assistant
•    def enroll(course, semester, role)
•     ...
•    end
•   end
•   class Student < Person
•    # A Student can enroll in a course for a semester
•    def enroll(course, semester)
•     ...
•    end
•   end                                                            #
Calling objects
• @course1 = Course.new("CPT","380","Beginning
  Ruby Programming","Lutes")
• @course2 = GradCourse.new("CPT","499d","Small
  Scale Digital Imaging","Mislan", "Spring")
• p @course1.to_s
• p @course2.to_s




                                                  #
Calling Objects
• @course1 that contains information
  about a Course
• @course2 is another instance variable,
  but it contains information about a
  GradClass object
•



                                           #
Arrays and hashes
•   fruit = ['Apple', 'Orange', 'Squash']
•   puts fruit[0]
•   fruit << 'Corn'
•   puts fruit[3]




                                            #
Arrays
• << will input a new element
• Last line outputs the new element




                                      #
Arrays More...
•   fruit = {
•     :apple => 'fruit',
•     :orange => 'fruit',
•     :squash => 'vegetable'
•   }
•   puts fruit[:apple]
•   fruit[:corn] = 'vegetable'
•   puts fruit[:corn]
                                 #
Arrays More...
• h = {"Red" => 1, "Blue" => 2, "Green" =>
  3}
• CORPORATE
• p h["Red"]
• Outpus -> 1
• h["Yellow"] = 4
• p h["Yellow"]
• Outputs -> 4
                                         #
Decision structures
•   age = 40
•   if age < 12
•     puts "You are too young to play"
•   elsif age < 30
•     puts "You can play for the normal price"
•   elsif age == 35
•     puts "You can play for free"
•   elsif age < 65
•     puts "You get a senior discount"
•   else
•     puts "You are too old to play"
•   end
                                                 #
while
• clock = 0
• while clock < 90
• puts "I kicked the ball to my team mate
  in the " + count.to_s + "
• minute of the match."
• clock += 1
• end

                                        #
Iterators
• fruit = ['Apple', 'Orange', 'Squash']
• fruit.each do |f|
• puts f
• end




                                          #
Iterators
• Keyword - do -
• Instance variable |f|
• Print f means print the instance of the
  loop




                                            #
Iterators
• fruit = ['Apple', 'Orange', 'Squash']
• fruit.each_with_index do |f,i|
• puts "#{i} is for #{f}"
• end
•



                                          #
Iterators
• Here f is the instance
• Index is i
• Will get two variables




                            #
Iterators
• fruit = ['Apple', 'Orange', 'Squash']
• for i in 0...fruit.length
• puts fruit[i]
• end
•



                                          #
Iterators
• For loop
• Same old syntax
• But 'each' loop is smart to handle an
  array
• 'each' dont need a max cutoff value.



                                          #
case...when
•   temperature = -88
•   case temperature
•     when -20...0
•             puts "cold“; start_heater
•     when 0...20
•             puts “moderate"
•     when 11...30
•             puts “hot”; drink_beer
•     else
•             puts "are you serious?"
•   end
                                          #
Exception handling
• begin
• @user = User.find(1)
• @user.name
• rescue
• STDERR.puts "A bad error occurred"
• end
•
                                       #
Thanks




         #

Mais conteúdo relacionado

Mais procurados (20)

Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Java script ppt
Java script pptJava script ppt
Java script ppt
 
Ruby programming
Ruby programmingRuby programming
Ruby programming
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
4.2 PHP Function
4.2 PHP Function4.2 PHP Function
4.2 PHP Function
 
Mysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sqlMysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sql
 
01 Php Introduction
01 Php Introduction01 Php Introduction
01 Php Introduction
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
 
Javascript
JavascriptJavascript
Javascript
 
Php technical presentation
Php technical presentationPhp technical presentation
Php technical presentation
 
Javascript
JavascriptJavascript
Javascript
 
Java script
Java scriptJava script
Java script
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
 

Destaque

Ruby Basics
Ruby BasicsRuby Basics
Ruby BasicsSHC
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails PresentationJoost Hietbrink
 
Lemme tell ya 'bout Ruby
Lemme tell ya 'bout RubyLemme tell ya 'bout Ruby
Lemme tell ya 'bout RubyArvin Jenabi
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on RailsEleni Huebsch
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on RailsAmit Patel
 
Sapphire Presentation for Review_CPG_Food.PPTX
Sapphire Presentation for Review_CPG_Food.PPTXSapphire Presentation for Review_CPG_Food.PPTX
Sapphire Presentation for Review_CPG_Food.PPTXJohn V. Counts Sr.
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on RailsManoj Kumar
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on RailsAgnieszka Figiel
 
Sapphire Presentation
Sapphire PresentationSapphire Presentation
Sapphire Presentationusama17
 

Destaque (14)

Ruby Basics
Ruby BasicsRuby Basics
Ruby Basics
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
Why Ruby
Why RubyWhy Ruby
Why Ruby
 
Lemme tell ya 'bout Ruby
Lemme tell ya 'bout RubyLemme tell ya 'bout Ruby
Lemme tell ya 'bout Ruby
 
Why I Love Ruby On Rails
Why I Love Ruby On RailsWhy I Love Ruby On Rails
Why I Love Ruby On Rails
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
 
Sapphire Presentation for Review_CPG_Food.PPTX
Sapphire Presentation for Review_CPG_Food.PPTXSapphire Presentation for Review_CPG_Food.PPTX
Sapphire Presentation for Review_CPG_Food.PPTX
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
 
Gemstones
GemstonesGemstones
Gemstones
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
 
Sapphire Presentation
Sapphire PresentationSapphire Presentation
Sapphire Presentation
 
Ruby on Rails for beginners
Ruby on Rails for beginnersRuby on Rails for beginners
Ruby on Rails for beginners
 
Gemstones
GemstonesGemstones
Gemstones
 

Semelhante a Introduction to Ruby

Rapid Application Development using Ruby on Rails
Rapid Application Development using Ruby on RailsRapid Application Development using Ruby on Rails
Rapid Application Development using Ruby on RailsSimobo
 
Front end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript coreFront end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript coreWeb Zhao
 
Continuous Integration For Rails Project
Continuous Integration For Rails ProjectContinuous Integration For Rails Project
Continuous Integration For Rails ProjectLouie Zhao
 
Refactoring Workshop (Rails Pacific 2014)
Refactoring Workshop (Rails Pacific 2014)Refactoring Workshop (Rails Pacific 2014)
Refactoring Workshop (Rails Pacific 2014)Bruce Li
 
Ruby 2: some new things
Ruby 2: some new thingsRuby 2: some new things
Ruby 2: some new thingsDavid Black
 
Ruby :: Training 1
Ruby :: Training 1Ruby :: Training 1
Ruby :: Training 1Pavel Tyk
 
Python.pptx
Python.pptxPython.pptx
Python.pptxAshaS74
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Wen-Tien Chang
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Wen-Tien Chang
 
并发模型介绍
并发模型介绍并发模型介绍
并发模型介绍qiang
 
Functional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented ProgrammersFunctional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented ProgrammersDiego Freniche Brito
 
Test First Teaching
Test First TeachingTest First Teaching
Test First TeachingSarah Allen
 
Linux Shell Scripting Craftsmanship
Linux Shell Scripting CraftsmanshipLinux Shell Scripting Craftsmanship
Linux Shell Scripting Craftsmanshipbokonen
 
Ruby Metaprogramming
Ruby MetaprogrammingRuby Metaprogramming
Ruby MetaprogrammingThaichor Seng
 
JS Fest 2019/Autumn. Daniel Ostrovsky. Falling in love with decorators ES6/Ty...
JS Fest 2019/Autumn. Daniel Ostrovsky. Falling in love with decorators ES6/Ty...JS Fest 2019/Autumn. Daniel Ostrovsky. Falling in love with decorators ES6/Ty...
JS Fest 2019/Autumn. Daniel Ostrovsky. Falling in love with decorators ES6/Ty...JSFestUA
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Mario Camou Riveroll
 

Semelhante a Introduction to Ruby (20)

Rapid Application Development using Ruby on Rails
Rapid Application Development using Ruby on RailsRapid Application Development using Ruby on Rails
Rapid Application Development using Ruby on Rails
 
Front end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript coreFront end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript core
 
Continuous Integration For Rails Project
Continuous Integration For Rails ProjectContinuous Integration For Rails Project
Continuous Integration For Rails Project
 
Refactoring Workshop (Rails Pacific 2014)
Refactoring Workshop (Rails Pacific 2014)Refactoring Workshop (Rails Pacific 2014)
Refactoring Workshop (Rails Pacific 2014)
 
Ruby 2: some new things
Ruby 2: some new thingsRuby 2: some new things
Ruby 2: some new things
 
Ruby :: Training 1
Ruby :: Training 1Ruby :: Training 1
Ruby :: Training 1
 
Ruby
RubyRuby
Ruby
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 
Javascript
JavascriptJavascript
Javascript
 
Python assignment help
Python assignment helpPython assignment help
Python assignment help
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽
 
Redis, Resque & Friends
Redis, Resque & FriendsRedis, Resque & Friends
Redis, Resque & Friends
 
并发模型介绍
并发模型介绍并发模型介绍
并发模型介绍
 
Functional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented ProgrammersFunctional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented Programmers
 
Test First Teaching
Test First TeachingTest First Teaching
Test First Teaching
 
Linux Shell Scripting Craftsmanship
Linux Shell Scripting CraftsmanshipLinux Shell Scripting Craftsmanship
Linux Shell Scripting Craftsmanship
 
Ruby Metaprogramming
Ruby MetaprogrammingRuby Metaprogramming
Ruby Metaprogramming
 
JS Fest 2019/Autumn. Daniel Ostrovsky. Falling in love with decorators ES6/Ty...
JS Fest 2019/Autumn. Daniel Ostrovsky. Falling in love with decorators ES6/Ty...JS Fest 2019/Autumn. Daniel Ostrovsky. Falling in love with decorators ES6/Ty...
JS Fest 2019/Autumn. Daniel Ostrovsky. Falling in love with decorators ES6/Ty...
 
Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?
 

Mais de Ranjith Siji

Wikipedia presentation full
Wikipedia presentation fullWikipedia presentation full
Wikipedia presentation fullRanjith Siji
 
Wikisource and schools malayalam community experience
Wikisource and schools   malayalam community experienceWikisource and schools   malayalam community experience
Wikisource and schools malayalam community experienceRanjith Siji
 
Introduction to mediawiki api
Introduction to mediawiki apiIntroduction to mediawiki api
Introduction to mediawiki apiRanjith Siji
 
Conduct a Wikipedia Edit a-thon
Conduct a Wikipedia Edit a-thonConduct a Wikipedia Edit a-thon
Conduct a Wikipedia Edit a-thonRanjith Siji
 
Black Holes and its Effects
Black Holes and its EffectsBlack Holes and its Effects
Black Holes and its EffectsRanjith Siji
 
Malayalam Computing tools and malayalam wikipedia
Malayalam Computing tools and malayalam wikipediaMalayalam Computing tools and malayalam wikipedia
Malayalam Computing tools and malayalam wikipediaRanjith Siji
 
Introduction to Computer Hardware Assembling
Introduction to Computer Hardware AssemblingIntroduction to Computer Hardware Assembling
Introduction to Computer Hardware AssemblingRanjith Siji
 
Introduction to Internet And Web
Introduction to Internet And WebIntroduction to Internet And Web
Introduction to Internet And WebRanjith Siji
 
Linux Alternative Softwares
Linux Alternative SoftwaresLinux Alternative Softwares
Linux Alternative SoftwaresRanjith Siji
 
Ubuntu 10.04 Installation Guide
Ubuntu 10.04 Installation GuideUbuntu 10.04 Installation Guide
Ubuntu 10.04 Installation GuideRanjith Siji
 
Introduction to Gnu/Linux
Introduction to Gnu/LinuxIntroduction to Gnu/Linux
Introduction to Gnu/LinuxRanjith Siji
 

Mais de Ranjith Siji (14)

Wikipedia presentation full
Wikipedia presentation fullWikipedia presentation full
Wikipedia presentation full
 
Wikisource and schools malayalam community experience
Wikisource and schools   malayalam community experienceWikisource and schools   malayalam community experience
Wikisource and schools malayalam community experience
 
Introduction to mediawiki api
Introduction to mediawiki apiIntroduction to mediawiki api
Introduction to mediawiki api
 
Conduct a Wikipedia Edit a-thon
Conduct a Wikipedia Edit a-thonConduct a Wikipedia Edit a-thon
Conduct a Wikipedia Edit a-thon
 
Black Holes and its Effects
Black Holes and its EffectsBlack Holes and its Effects
Black Holes and its Effects
 
Global warming
Global warmingGlobal warming
Global warming
 
Malayalam Computing tools and malayalam wikipedia
Malayalam Computing tools and malayalam wikipediaMalayalam Computing tools and malayalam wikipedia
Malayalam Computing tools and malayalam wikipedia
 
Introduction to Computer Hardware Assembling
Introduction to Computer Hardware AssemblingIntroduction to Computer Hardware Assembling
Introduction to Computer Hardware Assembling
 
Introduction to Internet And Web
Introduction to Internet And WebIntroduction to Internet And Web
Introduction to Internet And Web
 
Linux Alternative Softwares
Linux Alternative SoftwaresLinux Alternative Softwares
Linux Alternative Softwares
 
Ubuntu 10.04 Installation Guide
Ubuntu 10.04 Installation GuideUbuntu 10.04 Installation Guide
Ubuntu 10.04 Installation Guide
 
Introduction to Gnu/Linux
Introduction to Gnu/LinuxIntroduction to Gnu/Linux
Introduction to Gnu/Linux
 
FFMPEG TOOLS
FFMPEG TOOLSFFMPEG TOOLS
FFMPEG TOOLS
 
Linux Servers
Linux ServersLinux Servers
Linux Servers
 

Último

Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
[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
 
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
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
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
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
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
 

Último (20)

Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
[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
 
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
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
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
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
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
 

Introduction to Ruby

  • 2. What is Ruby ? • Ruby – Object Oriented Programming Language • Written 1995 by Yukihiro Matsumoto • Influenced by Python,Pearl,LISP • Easy to understand and workwith • Simple and nice syntax • Powerful programming capabilities #
  • 3. Advantages • Powerful And Expressive • Rich Library Support • Rapid Development • Open Source • Flexible and Dynamic
  • 4. Install Ruby • On Fedora – Rpms are available • ruby-1.8.6.287-8.fc11.i586 • ruby-devel • ruby-postgres • ruby-docs • ruby-racc • ruby-docs #
  • 5. Types • Command “ruby” • The extension is .rb #
  • 6. Ruby Documents • Command ri • Example – ri class – #
  • 7. helloPerson.rb • # First ruby programme • def helloPerson(name) • result = "Hello, " + name • return result • end • puts helloPerson("Justin") #
  • 8. Execute Programme • $ ruby helloPerson.rb • Hello, Justin • Nice and simple • Can use irb – interactive ruby shell • # is for comments like // #
  • 9. Ruby variables • def returnFoo • bar = "Ramone, bring me my cup." • return bar • end • puts returnFoo • #
  • 10. Kinds of Variables • Global variable - $ sign • instance variable - @ sign • Class Variable - @@ sign • Local Variable – no sign • Constants – Capital Letters #
  • 11. Global Variable • Available everywhere inside a programme • Not use frequently #
  • 12. instance variable • Unique inside an instance of a class • Truncated with instance • @apple = Apple.new • @apple.seeds = 15 • @apple.color = "Green" • #
  • 13. class Course Classes • def initialize(dept, number, name, professor) • @dept = dept • @number = number • @name = name • @professor = professor • end • def to_s • "Course Information: #@dept #@number - #@name [#@professor]" • end • def • self.find_all_students • ... • end • end #
  • 14. Classes • Initialize – is the constructor • Def – end -> function • Class-end -> class #
  • 15. Define Object • class Student • def login_student • puts "login_student is running" • end • private • def delete_students • puts "delete_students is running" • end • protected • def encrypt_student_password • puts "encrypt_student_password is running" • end • end #
  • 16. Define Object • @student = Student.new • @student.delete_students # This will fail • Because it is private • #
  • 17. Classes consist of methods and instance variables • class Coordinate • def initialize(x,y) #constructor • @x = x # set instance variables • @y = y • end • def to_s # string representation • "(#{@x},#{@y})" • end • end • point = Coordinate.new(1,5) • puts point • Will output (1,5) #
  • 18. Inheritance • class AnnotatedCoordinate < Coordinate • def initialize(x,y,comment) • super(x,y) • @comment = comment • end • def to_s • super + "[#@comment]" • end • End • a_point = • AnnotatedCoordinate.new(8,14,"Centre"); • puts a_point • Out Put Is -> (8,14)[Centre] #
  • 19. Inheritance • Inherit a parent class • Extend functions and variables • Add more features to base class #
  • 20. Polymorphism • The behavior of an object that varies depending on the input. • • #
  • 21. Polymorphism • class Person • # Generic features • end • class Teacher < Person • # A Teacher can enroll in a course for a semester as either • # a professor or a teaching assistant • def enroll(course, semester, role) • ... • end • end • class Student < Person • # A Student can enroll in a course for a semester • def enroll(course, semester) • ... • end • end #
  • 22. Calling objects • @course1 = Course.new("CPT","380","Beginning Ruby Programming","Lutes") • @course2 = GradCourse.new("CPT","499d","Small Scale Digital Imaging","Mislan", "Spring") • p @course1.to_s • p @course2.to_s #
  • 23. Calling Objects • @course1 that contains information about a Course • @course2 is another instance variable, but it contains information about a GradClass object • #
  • 24. Arrays and hashes • fruit = ['Apple', 'Orange', 'Squash'] • puts fruit[0] • fruit << 'Corn' • puts fruit[3] #
  • 25. Arrays • << will input a new element • Last line outputs the new element #
  • 26. Arrays More... • fruit = { • :apple => 'fruit', • :orange => 'fruit', • :squash => 'vegetable' • } • puts fruit[:apple] • fruit[:corn] = 'vegetable' • puts fruit[:corn] #
  • 27. Arrays More... • h = {"Red" => 1, "Blue" => 2, "Green" => 3} • CORPORATE • p h["Red"] • Outpus -> 1 • h["Yellow"] = 4 • p h["Yellow"] • Outputs -> 4 #
  • 28. Decision structures • age = 40 • if age < 12 • puts "You are too young to play" • elsif age < 30 • puts "You can play for the normal price" • elsif age == 35 • puts "You can play for free" • elsif age < 65 • puts "You get a senior discount" • else • puts "You are too old to play" • end #
  • 29. while • clock = 0 • while clock < 90 • puts "I kicked the ball to my team mate in the " + count.to_s + " • minute of the match." • clock += 1 • end #
  • 30. Iterators • fruit = ['Apple', 'Orange', 'Squash'] • fruit.each do |f| • puts f • end #
  • 31. Iterators • Keyword - do - • Instance variable |f| • Print f means print the instance of the loop #
  • 32. Iterators • fruit = ['Apple', 'Orange', 'Squash'] • fruit.each_with_index do |f,i| • puts "#{i} is for #{f}" • end • #
  • 33. Iterators • Here f is the instance • Index is i • Will get two variables #
  • 34. Iterators • fruit = ['Apple', 'Orange', 'Squash'] • for i in 0...fruit.length • puts fruit[i] • end • #
  • 35. Iterators • For loop • Same old syntax • But 'each' loop is smart to handle an array • 'each' dont need a max cutoff value. #
  • 36. case...when • temperature = -88 • case temperature • when -20...0 • puts "cold“; start_heater • when 0...20 • puts “moderate" • when 11...30 • puts “hot”; drink_beer • else • puts "are you serious?" • end #
  • 37. Exception handling • begin • @user = User.find(1) • @user.name • rescue • STDERR.puts "A bad error occurred" • end • #
  • 38. Thanks #