Let's Learn Ruby AQAP As Quickly As Possible!.  Run the interactive ruby shell – irb  Suggest using Netbeans – download ALL Running Ruby Code 2.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Introduction to Ruby.
Advertisements

Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Language of the Month If it’s December, it must be Ruby! Adam Coffman and Brent Beer.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Variables Pepper. Variable A variable –box –holds a certain type of value –value inside the box can change Example –A = 2B+1 –Slope = change in y / change.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
Introduction to a Programming Environment
Type Inference: CIS Seminar, 11/3/2009 Type inference: Inside the Type Checker. A presentation by: Daniel Tuck.
CHAPTER 3: CORE PROGRAMMING ELEMENTS Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
Introduction to Python and programming Michael Ernst UW CSE 190p Summer 2012.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
Ruby (on Rails) CSE 190M, Spring 2009 Week 1. The Players Kelly "Everyday I'm Hustlin' " Dunn Kim "Mouse" Todd Ryan "Papa T" Tucker.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
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.
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
INTERNET APPLICATION DEVELOPMENT For More visit:
Introduction to Python
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
CSD 340 (Blum)1 Ifs. CSD 340 (Blum)2 Page that asks user for background color and changes fore color from black if user selects black as background color.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
Ruby on Rails. What is Ruby? Programming Language Object-oriented Interpreted.
Problem Solving for Programming Session 8 Static Data Structures.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #005 (April somthin, 2015)
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
CS107 References and Arrays By Chris Pable Spring 2009.
What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports.
With Python.  One of the most useful abilities of programming is the ability to manipulate files.  Python’s operations for file management are relatively.
And other languages….  Array literals/initialization a = [1,2,3] a2 = [-10..0, 0..10] a3 = [[1,2],[3,4]] a4 = [w*h, w, h] a5 = [] empty = Array.new zeros.
Data Collections: Lists CSC 161: The Art of Programming Prof. Henry Kautz 11/2/2009.
1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter read appendix B (3 pages on DOS) and and.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
VARIABLES Programmes work by manipulating data placed in memory. The data can be numbers, text, objects, pointers to other memory areas, and more besides.
©John Samuel 2008 Introduction to PHP. ©John Samuel 2008 Objectives At the end of this class the student will be able to; Create and run a simple php.
RUBY by Ryan Chase.
OOP with Objective-C Categories, Protocols and Declared Properties.
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.
CRE Programming Club - Class 2 Robert Eckstein and Robert Heard.
Standard Types and Regular Expressions CS 480/680 – Comparative Languages.
Learning Ruby Classes. Variables Variables in Ruby can contain data of any type. You can use variables in your Ruby programs without any declarations.
Basic Scripting & Variables Yasar Hussain Malik - NISTE.
CMSC 202 Java Primer 1. July 24, 2007 Copyright © 2008 Pearson Addison-Wesley 2 A Sample Java Application.
Python 1 SIGCS 1 Intro to Python March 7, 2012 Presented by Pamela A Moore & Zenia C Bahorski 1.
Learning Ruby - 1 Let's Learn Ruby AQAP As Quickly As Possible!
Java: Variables and Methods By Joshua Li Created for the allAboutJavaClasses wikispace.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
Java-02 Basic Concepts Review concepts and examine how java handles them.
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,
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
PHP using MySQL Database for Web Development (part II)
Trace Tables In today’s lesson we will look at:
Chapter 2 Basic Computation
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)
Java Primer 1: Types, Classes and Operators
Variables, Expressions, and IO
Chapter 14 Introduction to Ruby.
Introduction to Java part 2
Ruby Testing 2, 11/9/2004.
PHP.
Introduction to Java part 2
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Class code for pythonroom.com cchsp2cs
Variables and Constants
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Let's Learn Ruby AQAP As Quickly As Possible!

 Run the interactive ruby shell – irb  Suggest using Netbeans – download ALL Running Ruby Code 2

/ 4  5 Float(22)/ / 4 3 * 3 3 ** 3 big_number = 1_000_000_000 (underscores not required and can go anywhere allowed to make it more readable – commas hard to see) Simple Ruby Number Objects 3

Math.sqrt( 9 ) Math.methods 9.methods  will tell you what methods can be used with 9 27.class  will tell you what class 27 belongs to (Fixnum) 3.times { print "Ho! " } 1.upto( 5 ) { |i| puts i }  defines i as the iterator variable termed a “code block” Anonymous delegate given the name i Ruby Number Methods 4

one = "1" two = "2" one + two  string concat, right? Integer( one ) + Integer( two )  casts and then adds 12.to_s  calls to string method, but wants you to request conversion print "Happy ", 12.to_s, "th Birthday!" puts "Happy ", 12.to_s, "th Birthday!" puts "Happy " "th Birthday!" Number Conversions 5

a1 = "this is a string\n”  evaluate backslash and contents of #{} inside of the string. Termed string interpolation a2 = 'and so is this\n‘  will see the \n as no evaluation is done print a1 print a2 answer = “joy” puts "The meaning of life is #{answer}" puts "There's #{24*60*60} seconds in a day" Ruby String Objects 6

formatted_text = <<END_OF_TEXT Let us turn our thoughts today To Martin Luther King And recognize that there are ties between us All men and women Living on the Earth Ties of hope and love Sister and brotherhood That we are bound together In our desire to see the world become A place in which our children Can grow free and strong END_OF_TEXT  any delimiter – as long as it matches print formatted_text  interpretation does work Ruby Here Documents 7

String.methods.sort  sorted list of String methods formatted_text.size  number of characters formatted_text.downcase  lowercase formatted_text.upcase  uppercase formatted_text.capitalize!  ! means to actually change the object in place (rather than return a changed copy) formatted_text.reverse  reverses all characters formatted_text.empty?  boolean indicated by ? only used in method names (not variables) Ruby String Methods 8

song_lines = formatted_text.to_a  to array (1..10).to_a  [1,2,3,4,5,6,7,8,9,10] from a range (denoted..) (‘a’..’e’).to_a  [“a”, “b”, “c”, “d”, “e”] print song_lines[1] print song_lines[5] print song_lines[99]  Gives nil if used when out of range, will add to array if assign outside of range. print song_lines print formatted_text song_lines.class  Array formatted_text.class  String Working with Ruby Strings 9

Same variable can hold any type at different times… a = 42 puts a a = "The Ruby Programming Language" puts a a = 1.8 puts a What About Variable Type? 10

 Everything - numbers, strings, data structures, Class itself etc. - is an object  Methods are invoked using the dot (".") notation  Variables are dynamically created as needed (problems with typos), but will tell you during execution if you access something without a value.  The traditional notion of a variable's "type" is not something the Ruby programmer concerns themselves with (too much) Ruby So Far 11