Ruby Getting started & Ruby.New Presented by Mario Tayah

Slides:



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

Introduction to Python Week 15. Try It Out! Download Python from Any version will do for this class – By and large they are all mutually.
Bioinformatics is … - the use of computers and information technology to assist biological studies - a multi-dimensional and multi-lingual discipline Chapters.
CS311 – Today's class Perl – Practical Extraction Report Language. Assignment 2 discussion Lecture 071CS Operating Systems I.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Perl Basics A Perl Tutorial NLP Course What is Perl?  Practical Extraction and Report Language  Interpreted Language Optimized for String Manipulation.
PHP Scripting Language. Introduction “PHP” is an acronym for “PHP: Hypertext Preprocessor.” It is an interpreted, server-side scripting language. Originally.
 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 Python
Introduction to Python Basics of the Language. Install Python Find the most recent distribution for your computer at:
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Ruby on Rails. What is Ruby? Programming Language Object-oriented Interpreted.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Smalltalk (and Squeak) Aida Dungan and Rick Shreve.
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.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
JavaScript Programming Unit #1: Introduction. What is Programming?
JavaScript Syntax, how to use it in a HTML document
Python Functions.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
XP Tutorial 8 Adding Interactivity with ActionScript.
Writing Scripts Hadi Otrok COEN 346.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
RUBY by Ryan Chase.
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
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?
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
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.
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
Perl Subroutines User Input Perl on linux Forks and Pipes.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
C# Part 1 Intro to C#. Background Designed to be simple, modern, general- purpose, OO, programming language Strong type checking, array bounds checking,
Few More Math Operators
C++ First Steps.
Development Environment
CS 330 Class 7 Comments on Exam Programming plan for today:
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)
Scope History of Ruby. Where can you use Ruby? General Features.
Introduction to Python
Chapter 2 - Introduction to C Programming
Introduction Python is an interpreted, object-oriented and high-level programming language, which is different from a compiled one like C/C++/Java. Its.
Pamela Moore & Zenia Bahorski
Variables, Expressions, and IO
The Linux Operating System
National Scientific Library at Tbilisi State University
Chapter 2 - Introduction to C Programming
Intro to PHP & Variables
Exception Handling Chapter 9.
What to do today: Brief history of Ruby General qualities/info
Python Primer 2: Functions and Control Flow
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
CS190/295 Programming in Python for Life Sciences: Lecture 6
Ruby Testing 2, 11/9/2004.
T. Jumana Abu Shmais – AOU - Riyadh
Web DB Programming: PHP
Quattor Advanced Tutorial, LAL
Intro to PHP.
CISC101 Reminders All assignments are now posted.
Functions continued.
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
CIS 136 Building Mobile Apps
Code Blocks, Closures, and Continuations
Presentation transcript:

Ruby Getting started & Ruby.New Presented by Mario Tayah April 14, 2006

installation Ruby comes with most mac os as well as linux distributions. Binary vs. build from source

binary Works out of the box www.rpmfind.net (rpm based linux) Debian dpkg you use #apt-cache search ruby interpreter #apt-get install ruby… Windows http://rubyinstaller.rubyforge.org

From source Download the source: Unpack : tar xzf snapshot.tar.gz http://www.ruby-lang.org Stable release: tarball format Stable snapshot (overnight) Nightly development: under development Unpack : tar xzf snapshot.tar.gz Then build and install depends on system you are using but usually it is something like: ./configure or make or make install…

Latest ruby version If you feel excited about ruby and want to put your hands on the currently developed version, you can have access to the repository of the development team. This is done through logging into anonymous@cvs.ruby-lang.org pass: enter you can check out the whole development tree, or the latest version, but definitely cannot check anything in. for more info about the commands to use for check out and for some additional options mirroring): www.cvshome.org, www.cvsup.org

Running ruby 2 ways: Command lines Def sum(n1,n2) n1+n2 end Sum(3,4) Programs, you can include this in a program and simply ask the ruby interpreter just as you do with any other scripting language.

doc Ruby standard library 9000 methods Use RDoc which is a system to extract documentation from within a ruby file and to an HTML document. Moreover, when you install ruby, you get help and documentation about the compiler as well as the libraries

Brief of OO in ruby Everything is an object, it has data and methods that manipulate that data. Even numbers are object. Ex: “hello”.lenght “Hello”.index(“e”) -1942.abs Class1.play(param)

Some def. State: variables Instances/receiver have identifiers (obj1) Methods (functions, messages) Methods are implemented using passing of messages to the instance. Constructor classinstance = class.new()

syntax No need for “;” “#” defines comments that runs until the end of the line Ignores empty spaces Invoke mrthod caller.method(params) note : no “;” You can sometimes not use the () for enclosing the params.

More syntax Local variables, method params, method names, start with lower case or _ Global var “$” Instance var start with an “@” Class variable start with an “@@” Class names, module names, constants start with an uppercase The rest of the expression can be any combination words, characters.

strings String are defined with “” or ‘’ ‘’ ruby simply takes what is inside the ‘’ as a string “” ruby takes into account escape characters “#{expression}” evaluates to the value of expression. Sub, gsub…(substitute…)

Arrays/hashes Arrays and hashes both grow as needed, they can hold any combination of types(all objects). Arrays provide faster access, hashes more flexible. Ex: a= [1,”hello”,2.1] Access a[index starting at 0] Out of bound indexing returns nil

Arrays/hashes Hashes are similar to arrays but indexed with user defined keys. Hashin = { ‘one’ =>’oneval’, ‘two’ => ‘twoval’ } Hashin[‘one’] Key and value are arbitrary types, key should be unique.

Control/structure If, while… they do not use() or{ they just use the “end” keyword to indicate the closing of a control statement/scope. Statement modifier: If x>0 Puts “danger” End Can be replaced by Puts “danger” if x>0

Regular expressions Regular expression are very useful, but rarely included in languages other than scripting languages. Regular expressions are expression like those that you usually see in old dos. Ex: *.*, x *… Ex: line.sub(/perl *p/,’python’) Substitutes every occ of perl zero or more spaces then a p with python.

Blocks and iterator Def call_block puts “start of method” yield puts “end of method” end call_block {puts “in block”} Will produce: Start of method In block End of method

Blocks and iterators [‘cat’,’dog’].each{|name| print name, “ ”} 5.times{print “*”}//print a * 5 times 3.upto(6){|i| print i}//prints 3 to 6 .

I/O puts // writes to the output // add new line print // writes to the output //no new line The above two can be used to write to any i/o object gets // new line of the standard input to the program

questions ?