SlideShare a Scribd company logo
“ A language that doesn’t affect the way you think about programming is not worth knowing”  — Alan Perlis
Ruby? HELL YEAH! htttp://syamantics.com
./toc What is Ruby? Installing Ruby Writing our first Ruby program Ruby v/s PHP Syntax What’s so special about Ruby??
What is Ruby? A dynamic, object-oriented programming language that is way too different than C-type languages. Inspired by LISP,  Perl, SmallTalk Simple, elegant, natural syntax Created by Yukihiro Matsumoto, a.k.a. Matz
Installing Ruby Windows http://rubyforge.org/frs/?group_id=167 Ubuntu sudo apt-get install ruby ri irb You can even try out ruby online! http://tryruby.hobix.com/
Our First Ruby Program Open Your Interactive Ruby Shell Open up Command Prompt/Shell/Terminal and type  irb , then hit enter. Now enter this, puts   "Hello World!"
Our Second Ruby Program # The Greeter class class   Greeter def   initialize (name   =   "World" ) @name   =   name end def   say_hi puts   "Hi  #{ @name } !" end def   say_bye puts   "Bye  #{ @name } , see you next week." end end # Initialize our Greeter g   =   Greeter.new   "Trippert Tech Session“ # Say hi g .say_hi # Say bye g .say_bye
Ruby v/s PHP Well, there are number of differences! Ruby is fully OOP, PHP is not. Ruby has got no primitive type, PHP has. In Ruby, classes are objects, In PHP, classes are classes. PHP function calls are Ruby messages. Ruby uses sigil denotes for variable scoping. Ruby has closures, anonymous functions, PHP does not*. … . And many many many more. There’s a create_function()  function in PHP to create anonymous function though  
Ruby Syntax : Branches if-else switch case if   xtra_large do_xtra_large elsif   large do_large elsif   medium do_medium else   #small do_small end do_xtra_large  if   xtra_large ending if
Ruby Syntax : Loops for in Iterators for   i   in   1. .. 10 print   i ,   " Hello\n" ; end projects   =   [ "Mobracer" ,   "GodFatherII" ,   "Tank" ,   "Madden Quiz" ] projects .each   do   |project|   puts   project end while i   =   5 while   i   >   0 puts   i i   -=   1 end
Ruby Syntax : Containers Arrays Hashes my_array   =   Array.new my_array   =   [] my_array .push   "One" my_array .push   "Two" my_array   =   [ "One" ,   "Two" , "Three" ,   "Four" ,   "Five" ] new_array   =   my_array[ 1. . 3 ] new_array   =   my_array[ 1 ,   3 ] people   =   {   "linus" =>{ "lname" => "Torvalds" ,   "fname" => "Linus" ,   "project" => "Linux" },   "matz" =>{ "lname" => "Matsumoto" ,   "fname" => "Yukihiro" ,   "project" => "Ruby" }, "DHH" =>{ "lname" => "Hanmer Heinsen" ,   "fname" => "David" ,   "project" => "RoR" }, "nate" =>{ "lname" => "Abel" ,   "fname" => "Nate" ,   "project" => "CakePHP" } } people .select   do   |nick,   info| puts   nick info .select   do   |key,   value| puts   key ,   value end end
Ruby Syntax : Subroutines, Modules Subroutines Modules def   doubleMe (   number   ) number   *   2 end puts   doubleMe   3 module   MyMath def   doubleMe (   number   ) number   *   2 end end include   MyMath puts   doubleMe   3 module   MyMath TWO   =   2 def   MyMath .doubleMe(   number   ) number   *   TWO end end include   MyMath puts   MyMath .doubleMe   3 Modules
Ruby Syntax : Classes and Objects Classes & Objects class   MyMath def   initialize @two   =   2 end def   doubleMe (number) number   *   @two end end my_math   =   MyMath.new puts   my_math .doubleMe   4
Ruby Syntax : Inheritance Extending A Class Including Modules class   MyParentMath def   initialize @two   =   2 end def   doubleMe (number) number   *   @two end end class   MyChildMath   <   MyParentMath def   quadropoleMe (number) doubleMe (number)   *   doubleMe(number) end end my_math   =   MyChildMath.new puts   my_math .quadropoleMe   4 module   MyMathModule TWO   =   2 def   doubleMe (number) number   *   TWO end end class   MyChildMath include   MyMathModule def   quadropoleMe (number) doubleMe (number)   *   doubleMe(number) end end my_math   =   MyChildMath.new puts   my_math .quadropoleMe   4
Ruby Syntax : Conventions ClassNames  method_names and variable_names  methods_asking_a_question?  slightly_dangerous_methods!  @instance_variables  $global_variables local_variable SOME_CONSTANTS or OtherConstants
What’s so special about Ruby?? Introspection  Close to Natural Language   Method Redefinition  Mixins Implicit   Singleton methods  Meta-programming  Dynamic typing No Primitives  Yield  Powerful  Fully Object Oriented  Flexible   Symbols   Minimalism   DRY  method_missing Hooks  Anonymous function  Modules  Multiple Inheritence  Blocks Reflection  Closures  Open objects   Classes are objects Dynamic   Operator Overloading   Open classes  Sigil Denotes Eval  Simplicity   Optional Parentheses  Iterators  attr_accessor Syntactic Sugar  Optional Punctuation  Write Less Do More
TBC...

More Related Content

What's hot (13)

PPT
Ruby for Perl Programmers
amiable_indian
 
PPT
name name2 n2.ppt
callroom
 
PPT
ppt9
callroom
 
PPT
name name2 n
callroom
 
PPT
name name2 n2
callroom
 
PDF
Ruby for Java Developers
Robert Reiz
 
KEY
Learn Ruby 2011 - Session 5 - Looking for a Rescue
James Thompson
 
PDF
Let's Learn Ruby - Basic
Eddie Kao
 
PDF
Blocks and loops.pptx
sandeep kumar
 
PDF
Ruby — An introduction
Gonçalo Silva
 
PPTX
Ruby Programming Language - Introduction
Kwangshin Oh
 
PPTX
Ruby introduction part1
Brady Cheng
 
PPT
The ruby programming language
praveen0202
 
Ruby for Perl Programmers
amiable_indian
 
name name2 n2.ppt
callroom
 
ppt9
callroom
 
name name2 n
callroom
 
name name2 n2
callroom
 
Ruby for Java Developers
Robert Reiz
 
Learn Ruby 2011 - Session 5 - Looking for a Rescue
James Thompson
 
Let's Learn Ruby - Basic
Eddie Kao
 
Blocks and loops.pptx
sandeep kumar
 
Ruby — An introduction
Gonçalo Silva
 
Ruby Programming Language - Introduction
Kwangshin Oh
 
Ruby introduction part1
Brady Cheng
 
The ruby programming language
praveen0202
 

Viewers also liked (11)

PDF
Как работодателю получить сертификат доверия от ГИТ
Директор по персоналу & Кадровое Дело
 
PPTX
Todo sobre halloween
emersonhernandezlozano
 
PPT
Speed Up Your Website
Anupom Syam
 
ODP
Nodejs
Anupom Syam
 
PPTX
ME 1770 Presentation
Evan Williamson
 
PPTX
Presentación de organizadores
Cristian0913
 
PPT
2009 Crofton DNT Thyroid Disruptors NBTS Meeting
KevinCrofton
 
PDF
GTAG: Documents de référence
ISACA Chapitre de Québec
 
PPTX
Anti patterns part 2
Return on Intelligence
 
PPTX
Biopesticide
Bijaya Kumar Uprety
 
Как работодателю получить сертификат доверия от ГИТ
Директор по персоналу & Кадровое Дело
 
Todo sobre halloween
emersonhernandezlozano
 
Speed Up Your Website
Anupom Syam
 
Nodejs
Anupom Syam
 
ME 1770 Presentation
Evan Williamson
 
Presentación de organizadores
Cristian0913
 
2009 Crofton DNT Thyroid Disruptors NBTS Meeting
KevinCrofton
 
GTAG: Documents de référence
ISACA Chapitre de Québec
 
Anti patterns part 2
Return on Intelligence
 
Biopesticide
Bijaya Kumar Uprety
 
Ad

Similar to Ruby Hell Yeah (20)

PDF
Agapornis Mansos - www.criadourosudica.blogspot.com
Antonio Silva
 
XLS
LoteríA Correcta
guest4dfcdf6
 
PPTX
Paulo Freire Pedagpogia 1
Alejandra Perez
 
PDF
MMBJ Shanzhai Culture
MobileMonday Beijing
 
PDF
Jerry Shea Resume And Addendum 5 2 09
gshea11
 
PDF
Washington Practitioners Significant Changes To Rpc 1.5
Oregon Law Practice Management
 
PPTX
Majlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi Petang
Imsamad
 
PPT
ppt30
callroom
 
PPT
ppt21
callroom
 
PPT
test ppt
callroom
 
PPT
ppt2
callroom
 
PPT
name name2 n
callroom
 
PPT
name name2 n
callroom
 
PPT
ppt17
callroom
 
PPT
ppt7
callroom
 
PPTX
Ruby for .NET developers
Max Titov
 
PPT
Intro To Ror
myuser
 
PPT
Ruby for C# Developers
Cory Foy
 
PPT
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
PPT
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
Agapornis Mansos - www.criadourosudica.blogspot.com
Antonio Silva
 
LoteríA Correcta
guest4dfcdf6
 
Paulo Freire Pedagpogia 1
Alejandra Perez
 
MMBJ Shanzhai Culture
MobileMonday Beijing
 
Jerry Shea Resume And Addendum 5 2 09
gshea11
 
Washington Practitioners Significant Changes To Rpc 1.5
Oregon Law Practice Management
 
Majlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi Petang
Imsamad
 
ppt30
callroom
 
ppt21
callroom
 
test ppt
callroom
 
ppt2
callroom
 
name name2 n
callroom
 
name name2 n
callroom
 
ppt17
callroom
 
ppt7
callroom
 
Ruby for .NET developers
Max Titov
 
Intro To Ror
myuser
 
Ruby for C# Developers
Cory Foy
 
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
Rubyforjavaprogrammers 1210167973516759-9
sagaroceanic11
 
Ad

Recently uploaded (20)

PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Advancing WebDriver BiDi support in WebKit
Igalia
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PPTX
Designing Production-Ready AI Agents
Kunal Rai
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Advancing WebDriver BiDi support in WebKit
Igalia
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Designing Production-Ready AI Agents
Kunal Rai
 

Ruby Hell Yeah

  • 1. “ A language that doesn’t affect the way you think about programming is not worth knowing” — Alan Perlis
  • 2. Ruby? HELL YEAH! htttp://syamantics.com
  • 3. ./toc What is Ruby? Installing Ruby Writing our first Ruby program Ruby v/s PHP Syntax What’s so special about Ruby??
  • 4. What is Ruby? A dynamic, object-oriented programming language that is way too different than C-type languages. Inspired by LISP, Perl, SmallTalk Simple, elegant, natural syntax Created by Yukihiro Matsumoto, a.k.a. Matz
  • 5. Installing Ruby Windows http://rubyforge.org/frs/?group_id=167 Ubuntu sudo apt-get install ruby ri irb You can even try out ruby online! http://tryruby.hobix.com/
  • 6. Our First Ruby Program Open Your Interactive Ruby Shell Open up Command Prompt/Shell/Terminal and type irb , then hit enter. Now enter this, puts &quot;Hello World!&quot;
  • 7. Our Second Ruby Program # The Greeter class class Greeter def initialize (name = &quot;World&quot; ) @name = name end def say_hi puts &quot;Hi #{ @name } !&quot; end def say_bye puts &quot;Bye #{ @name } , see you next week.&quot; end end # Initialize our Greeter g = Greeter.new &quot;Trippert Tech Session“ # Say hi g .say_hi # Say bye g .say_bye
  • 8. Ruby v/s PHP Well, there are number of differences! Ruby is fully OOP, PHP is not. Ruby has got no primitive type, PHP has. In Ruby, classes are objects, In PHP, classes are classes. PHP function calls are Ruby messages. Ruby uses sigil denotes for variable scoping. Ruby has closures, anonymous functions, PHP does not*. … . And many many many more. There’s a create_function() function in PHP to create anonymous function though 
  • 9. Ruby Syntax : Branches if-else switch case if xtra_large do_xtra_large elsif large do_large elsif medium do_medium else #small do_small end do_xtra_large if xtra_large ending if
  • 10. Ruby Syntax : Loops for in Iterators for i in 1. .. 10 print i , &quot; Hello\n&quot; ; end projects = [ &quot;Mobracer&quot; , &quot;GodFatherII&quot; , &quot;Tank&quot; , &quot;Madden Quiz&quot; ] projects .each do |project| puts project end while i = 5 while i > 0 puts i i -= 1 end
  • 11. Ruby Syntax : Containers Arrays Hashes my_array = Array.new my_array = [] my_array .push &quot;One&quot; my_array .push &quot;Two&quot; my_array = [ &quot;One&quot; , &quot;Two&quot; , &quot;Three&quot; , &quot;Four&quot; , &quot;Five&quot; ] new_array = my_array[ 1. . 3 ] new_array = my_array[ 1 , 3 ] people = { &quot;linus&quot; =>{ &quot;lname&quot; => &quot;Torvalds&quot; , &quot;fname&quot; => &quot;Linus&quot; , &quot;project&quot; => &quot;Linux&quot; }, &quot;matz&quot; =>{ &quot;lname&quot; => &quot;Matsumoto&quot; , &quot;fname&quot; => &quot;Yukihiro&quot; , &quot;project&quot; => &quot;Ruby&quot; }, &quot;DHH&quot; =>{ &quot;lname&quot; => &quot;Hanmer Heinsen&quot; , &quot;fname&quot; => &quot;David&quot; , &quot;project&quot; => &quot;RoR&quot; }, &quot;nate&quot; =>{ &quot;lname&quot; => &quot;Abel&quot; , &quot;fname&quot; => &quot;Nate&quot; , &quot;project&quot; => &quot;CakePHP&quot; } } people .select do |nick, info| puts nick info .select do |key, value| puts key , value end end
  • 12. Ruby Syntax : Subroutines, Modules Subroutines Modules def doubleMe ( number ) number * 2 end puts doubleMe 3 module MyMath def doubleMe ( number ) number * 2 end end include MyMath puts doubleMe 3 module MyMath TWO = 2 def MyMath .doubleMe( number ) number * TWO end end include MyMath puts MyMath .doubleMe 3 Modules
  • 13. Ruby Syntax : Classes and Objects Classes & Objects class MyMath def initialize @two = 2 end def doubleMe (number) number * @two end end my_math = MyMath.new puts my_math .doubleMe 4
  • 14. Ruby Syntax : Inheritance Extending A Class Including Modules class MyParentMath def initialize @two = 2 end def doubleMe (number) number * @two end end class MyChildMath < MyParentMath def quadropoleMe (number) doubleMe (number) * doubleMe(number) end end my_math = MyChildMath.new puts my_math .quadropoleMe 4 module MyMathModule TWO = 2 def doubleMe (number) number * TWO end end class MyChildMath include MyMathModule def quadropoleMe (number) doubleMe (number) * doubleMe(number) end end my_math = MyChildMath.new puts my_math .quadropoleMe 4
  • 15. Ruby Syntax : Conventions ClassNames method_names and variable_names methods_asking_a_question? slightly_dangerous_methods! @instance_variables $global_variables local_variable SOME_CONSTANTS or OtherConstants
  • 16. What’s so special about Ruby?? Introspection Close to Natural Language Method Redefinition Mixins Implicit Singleton methods Meta-programming Dynamic typing No Primitives Yield Powerful Fully Object Oriented Flexible Symbols Minimalism DRY method_missing Hooks Anonymous function Modules Multiple Inheritence Blocks Reflection Closures Open objects Classes are objects Dynamic Operator Overloading Open classes Sigil Denotes Eval Simplicity Optional Parentheses Iterators attr_accessor Syntactic Sugar Optional Punctuation Write Less Do More