Getting Started with Ruby - PowerPoint PPT Presentation

About This Presentation
Title:

Getting Started with Ruby

Description:

For example, try puts -1.abs. Derives strengths of Perl, Smalltalk, Python ... IDEs. Comes with FreeRIDE IDE. Mondrian IDE. TextPad generally used on Mac ... – PowerPoint PPT presentation

Number of Views:103
Avg rating:3.0/5.0
Slides: 22
Provided by: venkatsub
Learn more at: https://www2.cs.uh.edu
Category:
Tags: getting | ides | ruby | started

less

Transcript and Presenter's Notes

Title: Getting Started with Ruby


1
Getting Started with Ruby
2
Whats Ruby?
  • Ruby is an OO, dynamic, agile language
  • Everythings an object
  • For example, try puts -1.abs
  • Derives strengths of Perl, Smalltalk, Python
  • Created by Matz in mid 90s
  • Prevalent in Japan recent buzz in the US
  • Its a lightweight language
  • Clean, Higher signal-to-noise ratio
  • There is no compiler to stand in your way
  • Quite flexibleyoull see when you use it

3
History
  • Created by Yukihiro Matsumoto (Matz) in 1993
  • Slowly being accepted in the west
  • Popularized by some key players in the industry
  • Gaining strength in various applications
  • Ruby-On-Rails (ROR)

4
Downloading Ruby
  • Ruby site
  • http//www.ruby-lang.org
  • For windows, you may use one-click installer
    http//rubyinstaller.rubyforge.org

5
Ruby Version
  • You can find the version of ruby youre using by
    typing ruby v

6
Running Ruby
  • Run ruby and type commands
  • Interactively using irb
  • Save code to file and run it
  • Ill run it directly from notepad2
  • Other tools and Plugins available as well

7
IDEs
  • Comes with FreeRIDE IDE
  • Mondrian IDE
  • TextPad generally used on Mac
  • Command line and Notepad(2) works great as well!
  • The following blog entry shows you how
  • http//tinyurl.com/as8z7

8
Documentation
  • ri
  • RDoc at http//www.ruby-doc.org

9
Object-Oriented
  • Ruby treats almost everything as objects
  • nil is an object (try puts nil.methods)
  • Even classes are objects!
  • You use them like objects
  • These objects simply represent their class

Pizza is a const that references Pizza class
object
10
Less Clutter
  • Code less, do more
  • Java
  • Ruby

GOJ
11
Less Clutter
  • Clean language
  • Less noise
  • is not needed
  • Parenthesis are optional
  • Variables dont have type specification
  • Last statement of a method returns automatically
  • You can even return multiple values!

12
Variables
  • Dynamic typing
  • Output

13
Types
  • Everything is an object

14
Writing a function
15
Another function
Returns an array
Assigns elements of array to individual variables
16
Ruby Conventions
  • Conventions are very important
  • Sometimes convention simply makes code look
    better
  • At other times, it means something significant
    you will learn some conventions the hard way ?

17
Class/Method conventions
  • Class names, modules names, and constants start
    with upper case
  • SportsCar, ValueOfPI, DAYS_IN_WEEK
  • Methods and variables start with lowercase and
    use underscore
  • start_engine(), miles_driven
  • Instance variables have _at_
  • _at_fuel_level
  • Class variables use double ats
  • _at__at_suggested_pressure
  • Global variables use
  • ozone

18
Method convention talks to you
  • You can figure out what a method is up to from
    its looks
  • Methods may end with an
  • the method may appear as l-value

Query method
Doesnt modify object
Has side effect mutates object
19
Global and Predefined Variables
  • This is hideous
  • You may be setting some global variable and not
    know it (familiarize yourself)
  • Some predefs _, 0, , , !,

20
"" vs '' (Double vs. Single Quotes)
  • '' is a simple string
  • Expressions within "" are evaluated
  • Better to use ' if you dont have expressions

21
More on Strings
Write a Comment
User Comments (0)
About PowerShow.com