Learn Ruby 2011 - Session 2
Upcoming SlideShare
Loading in...5
×
 

Learn Ruby 2011 - Session 2

on

  • 723 views

In our second session we began the first half of our language crash course. This session covered Classes vs. Objects, Duck Typing, Variables, Strings and Methods.

In our second session we began the first half of our language crash course. This session covered Classes vs. Objects, Duck Typing, Variables, Strings and Methods.

Statistics

Views

Total Views
723
Views on SlideShare
722
Embed Views
1

Actions

Likes
1
Downloads
14
Comments
0

1 Embed 1

http://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

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
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Learn Ruby 2011 - Session 2 Learn Ruby 2011 - Session 2 Presentation Transcript

  • Learn Ruby 2011 Session 2
  • Our SponsorsFlatsourcing, iSeatz, Koda, and Launchpad
  • Welcome Back Ready to learn some Ruby? View slide
  • Our Books View slide
  • Learn to Program, 2ed• For total beginners• Systematic coverage of programming concepts• Uses Ruby to teach programming
  • Programming Ruby, 3ed• Comprehensive langauge reference• Covers Ruby 1.9.2, annotations for 1.9 and 1.9.2 specific features• de facto standard reference
  • Language Crashing Learning the basics in pieces
  • Objects vs Classes• An Object is a discreet thing• You can do things to Objects• Classes tell you how to build Objects• Classes in Ruby are also Objects
  • Objects vs Classes• A Car is a Class• My Car is an Object• My Car has lots of things in common with other cars• So, My Car is a Car• But, Not every Car is My Car
  • Everything is an Object• In Ruby everything is an object• This means you can do things to everything you come across.
  • Everything has a Class• Because everything is an Object, everything also has a class• An Object’s class is often referred to as it’s Type
  • Duck Typing• Ruby is Duck Typed• This means that when you encounter an Object in Ruby, what you can do to it determines it’s type• Ruby’s “Type Model” is concerned with what you can do with Objects
  • A Sample of Rubydef say_goodnight(name) result = “Good night, “ + name return resultendputs say_goodnight(“John-Boy”)puts say_goodnight(“Mary-Ellen”)
  • Variablesdef say_goodnight(name) result = “Good night, “ + name return resultendputs say_goodnight(“John-Boy”)puts say_goodnight(“Mary-Ellen”)
  • Variables• Variables hold values, in Ruby they hold Objects• Variables are the handles we use to easily reference the data we want to work with
  • Variables• There are four basic kinds of variables • local_variables • @instance_variables • @@class_variables • $global_variables
  • Variables• There are also Constants, variables that don’t change • ClassNames • CONSTANT_NAME
  • Variablesdef say_goodnight(name) result = “Good night, “ + name return resultendputs say_goodnight(“John-Boy”)puts say_goodnight(“Mary-Ellen”)
  • Stringsdef say_goodnight(name) result = “Good night, “ + name return resultendputs say_goodnight(“John-Boy”)puts say_goodnight(“Mary-Ellen”)
  • Strings• Strings in Ruby come in two basic kinds • “Double-Quoted” • ‘Single-Quoted’• They differ in how much processing Ruby does with their contents
  • ‘Single-Quoted’ Strings• Ruby does nothing with this kind of string, no interpolation, no escape processing, nothing
  • “Double-Quoted” Strings• Ruby performs additional processing of these strings • Ruby looks for escape sequences n t u2603 • Ruby also performs interpolation #{expression}
  • Stringsdef say_goodnight(name) result = “Good night, #{name}“ return resultendputs say_goodnight(“John-Boy”)puts say_goodnight(“Mary-Ellen”)
  • Methodsdef say_goodnight(name) result = “Good night, #{name}“ return resultendputs say_goodnight(“John-Boy”)puts say_goodnight(“Mary-Ellen”)
  • Methods• Methods are reusable bits of code• They also go by the name Functions.• They accept parameters, do something and return a value
  • Methods• Parameters are passed to methods and given convenient local variable names by the method definition
  • Methodsdef say_goodnight(name) result = “Good night, #{name}“ return resultendputs say_goodnight(“John-Boy”)puts say_goodnight(“Mary-Ellen”)
  • Methods• When calling methods the parentheses that surround parameters are optional.• Only leave them out when unambiguous
  • Methodsdef say_goodnight name result = “Good night, #{name}“ return resultendputs say_goodnight “John-Boy”puts(say_goodnight “Mary-Ellen”)
  • Methods• Methods return values can be either explicit or implicit• Use the return keyword to make explicit what your methods return• Or, the last expression in the method will be the methods return value
  • Methodsdef say_goodnight name result = “Good night, #{name}“endputs say_goodnight “John-Boy”puts(say_goodnight “Mary-Ellen”)
  • Our Simplified Sampledef say_goodnight(name) “Good night, #{name}“endputs say_goodnight(“John-Boy”)puts say_goodnight(“Mary-Ellen”)
  • Reviewing• Objects vs. Classes• Duck Typing• Variables• Strings• Methods
  • For Next WeekFor the New to Programming• Read Chapters 2, 3 & 4 in LtP• Complete exercises for each chapterFor Everyone• Read Chapter 2 in PR1.9• Keep playing in IRB
  • Next Week• Arrays & Hashes• Symbols• Control Structures• Regular Expressions• Blocks & Iterators