Ruby (on Rails) CSE 190M, Spring 2009 Week 1. The Players Kelly "Everyday I'm Hustlin' " Dunn Kim "Mouse" Todd Ryan "Papa T" Tucker.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Ruby (on Rails) CSE 190M, Spring 2009 Week 2. Arrays Similar to PHP, Ruby arrays… – Are indexed by zero-based integer values – Store an assortment of.
Introducing JavaScript
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Loops – While, Do, For Repetition Statements Introduction to Arrays
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Week 1 basic Python programs, defining functions Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where.
Python Crash Course by Monica Sweat. Python Perspective is strongly typed, interpreted language is used to define scripts (Don't even need to define a.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed.
String Escape Sequences
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Game Programming © Wiley Publishing All Rights Reserved. The L Line The Express Line to Learning L Line L.
Ruby (on Rails) CSE 190M, Spring 2009 Week 2. Arrays Similar to PHP, Ruby arrays… – Are indexed by zero-based integer values – Store an assortment of.
The Ruby Programming Language
Python.
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
Introduction to Python
Ruby! Useful as a scripting language – script: A small program meant for one time use – Targeted towards small to medium size projects Use by: – Amazon,
INTRODUCTION TO ALGORITHMS PROGRAMMING. Objectives Give a definition of the term algorithm Describe the various parts of the pseudocode algorithm or algorithm.
PYTHON. Python is a high-level, interpreted, interactive and object- oriented scripting language. Python was designed to be highly readable which uses.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
CS 330 Programming Languages 11 / 21 / 2006 Instructor: Michael Eckmann.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Ruby on Rails. What is Ruby? Programming Language Object-oriented Interpreted.
What does a computer program look like: a general overview.
Flow of Control Part 1: Selection
EIW - ASP Introduction1 Active Server Pages VBScript.
Q and A for Sections 2.9, 4.1 Victor Norman CS106 Fall 2015.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
CSE 154 LECTURE 5: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Week 1 basic Python programs, defining functions Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where.
Unit 1 Basic Python programs, functions Special thanks to Roy McElmurry, John Kurkowski, Scott Shawcroft, Ryan Tucker, Paul Beck for their work. Except.
Week 2 expressions, variables, for loops Special thanks to Scott Shawcroft, Ryan Tucker, Paul Beck, Hélène Martin, Kim Todd, John Kurkowski, and Marty.
RUBY by Ryan Chase.
Ruby. What is Ruby? Programming Language Object-oriented Interpreted Popular- Ruby on Rails a framework for Web Server Programming.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
Ruby: An Introduction Created by Yukihiro Matsumoto in 1993 (named after his birthstone) Pure OO language (even the number 1 is an instance of a class)
Introduction to Computer Science / Procedural – 67130
Variables, Expressions, and IO
Outline Altering flow of control Boolean expressions
T. Jumana Abu Shmais – AOU - Riyadh
expressions, variables, for loops
expressions, variables, for loops
Introduction to Programming with Python
CISC101 Reminders All assignments are now posted.
Introducing JavaScript
Unit 3: Variables in Java
Comparing Python and Java
Introduction to Python
Presentation transcript:

Ruby (on Rails) CSE 190M, Spring 2009 Week 1

The Players Kelly "Everyday I'm Hustlin' " Dunn Kim "Mouse" Todd Ryan "Papa T" Tucker

About the Section Introduce the Ruby programming language Use Ruby to template web pages Learn about Ruby on Rails and its benefits

What is Ruby? Programming Language Object-oriented Interpreted

Interpreted Languages Not compiled like Java Code is written and then directly executed by an interpreter Type commands into interpreter and see immediate results Computer Runtime Environment CompilerCode Java: ComputerInterpreterCode Ruby:

What is Ruby on Rails (RoR) Development framework for web applications written in Ruby Used by some of your favorite sites!favorite sites

Advantages of a framework Standard features/functionality are built-in Predictable application organization – Easier to maintain – Easier to get things going

Installation Windows – Navigate to: lang.org/en/downloads/ lang.org/en/downloads/ – Scroll down to "Ruby on Windows" – Download the "One-click Installer" – Follow the install instructions Include RubyGems if possible (this will be necessary for Rails installation later) Mac/Linux – Probably already on your computer – OS X 10.4 ships with broken Ruby! Go here… mysql-osx mysql-osx

hello_world.rb puts "hello world!"

puts vs. print "puts" adds a new line after it is done – analogous System.out.println() "print" does not add a new line – analogous to System.out.print()

Running Ruby Programs Use the Ruby interpreter ruby hello_world.rb – “ruby” tells the computer to use the Ruby interpreter Interactive Ruby (irb) console irb – Get immediate feedback – Test Ruby features

Comments # this is a single line comment =begin this is a multiline comment nothing in here will be part of the code =end

Variables Declaration – No need to declare a "type" Assignment – same as in Java Example: x = "hello world"# String y = 3# Fixnum z = 4.5# Float r = 1..10# Range

Objects Everything is an object. – Common Types (Classes): Numbers, Strings, Ranges – nil, Ruby's equivalent of null is also an object Uses "dot-notation" like Java objects You can find the class of any variable x = "hello" x.class  String You can find the methods of any variable or class x = "hello" x.methods String.methods

Objects (cont.) There are many methods that all Objects have Include the "?" in the method names, it is a Ruby naming convention for boolean methods nil? eql?/equal? ==, !=, === instance_of? is_a? to_s

Numbers Numbers are objects Different Classes of Numbers – FixNum, Float 3.eql?2  false -42.abs  round  rount  ceil  floor  3 3.zero?  false

String Methods "hello world".length  11 "hello world".nil?  false "".nil?  false "ryan" > "kelly"  true "hello_world!".instance_of?String  true "hello" * 3  "hellohellohello" "hello" + " world"  "hello world" "hello world".index("w")  6

Operators and Logic Same as Java – Multiplication, division, addition, subtraction, etc. Also same as Java AND Python (WHA?!) – "and" and "or" as well as "&&" and "||" Strange things happen with Strings – String concatenation (+) – String multiplication (*) Case and Point: There are many ways to solve a problem in Ruby

if/elsif/else/end Must use "elsif" instead of "else if" Notice use of "end". It replaces closing curly braces in Java Example: if (age < 35) puts "young whipper-snapper" elsif (age < 105) puts "80 is the new 30!" else puts "wow… gratz..." end

Inline "if" statements Original if-statement if age < 105 puts "don't worry, you are still young" end Inline if-statement puts "don't worry, you are still young" if age < 105

for-loops for-loops can use ranges Example 1: for i in puts i end Can also use blocks (covered next week) 3.times do puts "Ryan! " end

for-loops and ranges You may need a more advanced range for your for-loop Bounds of a range can be expressions Example: for i in 1..(2*5) puts i end

while-loops Can also use blocks (next week) Cannot use "i++" Example: i = 0 while i < 5 puts i i = i + 1 end

unless "unless" is the logical opposite of "if" Example: unless (age >= 105)# if (age < 105) puts "young." else puts "old." end

until Similarly, "until" is the logical opposite of "while" Can specify a condition to have the loop stop (instead of continuing) Example i = 0 until (i >= 5) # while (i < 5), parenthesis not required puts I i = i + 1 end

Methods Structure def method_name( parameter1, parameter2, …) statements end Simple Example: def print_ryan puts "Ryan" end

Parameters No class/type required, just name them! Example: def cumulative_sum(num1, num2) sum = 0 for i in num1..num2 sum = sum + i end return sum end # call the method and print the result puts(cumulative_sum(1,5))

Return Ruby methods return the value of the last statement in the method, so… def add(num1, num2) sum = num1 + num2 return sum end can become def add(num1, num2) num1 + num2 end

User Input "gets" method obtains input from a user Example name = gets puts "hello " + name + "!" Use chomp to get rid of the extra line puts "hello" + name.chomp + "!" chomp removes trailing new lines

Changing types You may want to treat a String a number or a number as a String to_i – converts to an integer (FixNum) to_f – converts a String to a Float to_s – converts a number to a String Examples "3.5".to_i  3 "3.5".to_f  to_s  "3"

Constants In Ruby, constants begin with an Uppercase They should be assigned a value at most once This is why local variables begin with a lowercase Example: Width = 5 def square puts ("*" * Width + "\n") * Width end

Week 1 Assignment Do the Space Needle homework from 142 in Ruby /08au/homework/2/spec.pdf /08au/homework/2/spec.pdf DOES need to scale using a constant Use syntax that is unique to Ruby whenever possible Expected output can be found under the Homework 2 Section /08au/homework.shtml /08au/homework.shtml

References Web Sites – – Books – Programming Ruby: The Pragmatic Programmers' Guide ( – Agile Web Development with Rails – Rails Recipes – Advanced Rails Recipes