Section with Kiyoshi (Slides adapted from Harrison Ting’s) Ruby!

Slides:



Advertisements
Similar presentations
Chapter 25 Perl and CGI (Common Gateway Interface)
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Introduction to Ruby.
Module 6: Introduction to C Language ITEI102 Introduction to Programming Structure of C++ Program - Programming Terminologies - Microsoft Visual Studio.
Introduction to Computer Programming in C
Perl Basics A Perl Tutorial NLP Course What is Perl?  Practical Extraction and Report Language  Interpreted Language Optimized for String Manipulation.
CS 497C – Introduction to UNIX Lecture 10: The vi/vim Editor Chin-Chih Chang
CS 497C – Introduction to UNIX Lecture 3: Inside UNIX Chin-Chih Chang
Guide To UNIX Using Linux Third Edition
Scripting with Ruby What is a scripting language? What is Ruby?
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
Introduction to Ruby CSE 413 Autumn 2008 Credit: Dan Grossman, CSE341.
Chapter 1: Python Basics CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
A First Program Using C#
CMSC 330: Organization of Programming Languages Ruby Hash Tables (and other topics)
CS 240 Week 3. List’Em java Grep [-r] directoryName fileSelectionPattern substringSelectionPattern Run Demo java LineCount [-r] directoryName fileSelectionPattern.
Computer Concepts 7th Edition Parsons/Oja Chapter 3 Computer Software Section A: Software Basics.
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
Introduction to Ruby WING Group Meeting 9 Jun 2006 Min-Yen Kan WING Group Meeting 9 Jun 2006 Min-Yen Kan.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.
Ruby on Rails WTF? Created by Matz in 1993 Inspired by Smalltalk Rubygems = CSPAN Rake = ant Rdoc = javadoc.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Regular Expressions in Perl CS/BIO 271 – Introduction to Bioinformatics.
Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.
(A Very Short) Introduction to Shell Scripts CSCI N321 – System and Network Administration Copyright © 2000, 2003 by Scott Orr and the Trustees of Indiana.
Created by Harry H. Cheng,  2009 McGraw-Hill, Inc. All rights reserved. C for Engineers and Scientists: An Interpretive Approach Chapter 2: Getting Started.
CS 330 Programming Languages 10 / 02 / 2007 Instructor: Michael Eckmann.
Scripting with Ruby What is a scripting language? What is Ruby?
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
TCL TK. Tcl/Tk C functions can become Tcl commands that are invoked interactively Tk = scriptable, portable user interface –Windows, X (Unix), MacOS,
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.
Scripting with Ruby What is a scripting language? What is Ruby?
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Guide to filenames. FilenameTopic RubyBasicsExpressions, strings, etc.
REFERENCE: CHAPTER 1 High-level languages + Python.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
1 Getting Started with Ruby. 2 What’s Ruby? Ruby is an OO, dynamic, agile language –Everything’s an object For example, try puts -1.abs –Derives strengths.
Linux+ Guide to Linux Certification, Second Edition
Introduction to information systems RUBY dr inż. Tomasz Pieciukiewicz.
PZ02CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02CX - Perl Programming Language Design and Implementation.
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
CMSC330 More Ruby. Last lecture Scripting languages Ruby language –Implicit variable declarations –Many control statements –Classes & objects –Strings.
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
Chapter 5: Looping. Using the while Loop Loop – A structure that allows repeated execution of a block of statements Loop body – A block of statements.
Introduction to Scripting Workshop February 23, 2016.
Presented By P.SRIVIDYA 085D1A0552 Programming Language.
1 Sections 3.1 – 3.2a Basic Syntax and Semantics Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Ruby Getting started & Ruby.New Presented by Mario Tayah
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)
Perl Programming Language Design and Implementation (4th Edition)
Ruby Demo Code Guide to filenames.
Chapter 5: Repetition Structures
CS 403: Programming Languages
Henning Schulzrinne Advanced Programming
Chapter 14 Introduction to Ruby.
The ‘grep’ Command Colin Masterson.
The Linux Command Line Chapter 7
Ruby Testing 2, 11/9/2004.
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
Ruby Classes.
Ruby Containers, Iterators, and Blocks
Code Blocks, Closures, and Continuations
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Section with Kiyoshi (Slides adapted from Harrison Ting’s) Ruby!

Readings The Ruby Programming Language Read Chapter 1 Skim Chapters 2-7 Read sections 8.9 and 8.10

Running ruby ruby: execute from command line – ruby myProgram.rb irb : interactive command line interpreter – Write program in the command line or… – Import ruby file: source ‘myProgram.rb’ – Run ruby file: load ‘myProgram.rb’ SciTE: IDE bundled with ruby install – Sorry Mac and linux users, Windows only – Edit – Execute

Example #1: Classes Files: – greeter.rb – spanishGreeter.rb – copyGreeter.rb – greeterCounter.rb Constructor Instance methods and variables Subclassing – Inheritance – super Class methods and variables

Example #2: Control Files – printTwice.rb Adding a method to a class

Example #3: Control cont. Files – firstElement.rb – firstElementWithYield.rb – firstElementWithYieldAndEnumerable.rb Adding a method to a module Blocks and Iterators yield – Can yield more than one value

Example #4: eval ’s Files – eval.rb – classEval.rb eval vs. class_eval – class_eval executes in the context of the class – eval executes in the current context

Example #5: Regular Expressions Use for pattern matching

Regular Expressions cont. Literals – /1/.match("012") – matches – "012".match(/1/) – does the same thing – /1/.match("789") – doesn’t match

Regular Expressions cont. Character classes – /[db]og/.match("dog") – /[db]og/.match("bog") – /[0-9]/.match("Ruby 123") – /[a-z]/.match("Ruby 123") – /[A-Z]/.match("Ruby 123") – /[a-zA-Z0-9]/.match("Ruby 123") – /[^Rub]/.match("Ruby 123")

Regular Expressions cont. Special character class: “.” – /.og/.match("dog")

Regular Expressions cont. Repetition – “?” matches 0 or 1 /ruby?/.match("rub") /ruby?/.match("rubyyy") – “*” matches 0 or more /ruby*/.match("rub") /ruby*/.match("rubyyy") – “+” matches 1 or more /ruby+/.match("rub") /ruby+/.match("rubyyy")

Regular Expressions cont. Putting it all together – /[aeiou]+/.match("aardvark")

Regular Expressions cont. (, ), [, ], {, },., ?, +, *, |, ^, $, \ have special meaning – Escape each one to use it literally Files – regexp.rb See section 9.2 for more information

Example #6: Sorting Files – absoluteSort.rb

Example #7: method_missing Files – methodMissing.rb

Example #8: Hash Files – hashMe.rb

Questions?