• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Ruby Hell Yeah
 

Ruby Hell Yeah

on

  • 2,204 views

Introduction to Ruby basics and Ruby idioms.

Introduction to Ruby basics and Ruby idioms.

Statistics

Views

Total Views
2,204
Views on SlideShare
2,124
Embed Views
80

Actions

Likes
2
Downloads
13
Comments
0

5 Embeds 80

http://www.syamantics.com 54
http://syamantics.com 20
http://174.143.27.153 3
http://www.linkedin.com 2
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Ruby Hell Yeah Ruby Hell Yeah Presentation Transcript

    • “ 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 " ;
    • 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...