Introduction to information systems RUBY dr inż. Tomasz Pieciukiewicz.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Introduction to Ruby.
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.
Introduction to the C# Programming Language for the VB Programmer.
Chapter Day 5. © 2007 Pearson Addison-Wesley. All rights reserved2-2 Agenda Day 5 Questions from last Class?? Problem set 1 Posted  Introduction on developing.
Intro to Robots Robots are Everywhere. Intro to Robots Various robots in use today lawnmower pet baby seal for convalescents gutter cleaner home security.
10 November JavaScript. Presentation Hints What do YOU think makes a good presentation Some of my suggestions Don’t write full sentences on slides Talk,
1 Chapter 2 Introductory Programs. 2 Getting started To create and run a Java program –Create a text file with a.java extension for the source code. For.
JavaScript, Third Edition
ASP.NET Programming with C# and SQL Server First Edition
Scripting with Ruby What is a scripting language? What is Ruby?
JaySummet IPRE Python Review 2. 2 Outline Compound Data Types: Strings, Tuples, Lists & Dictionaries Immutable types: Strings Tuples Accessing.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Ruby (on Rails) CSE 190M, Spring 2009 Week 1. The Players Kelly "Everyday I'm Hustlin' " Dunn Kim "Mouse" Todd Ryan "Papa T" Tucker.
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
JS Arrays, Functions, Events Week 5 INFM 603. Agenda Arrays Functions Event-Driven Programming.
SCRIPTING IN RUBY By Amber Bennett “Ruby is simple in appearance, but is very complex inside, just like our human body.” --Yukihiro Matsumoto.
Introduction to Python
Perl Tutorial Presented by Pradeepsunder. Why PERL ???  Practical extraction and report language  Similar to shell script but lot easier and more powerful.
Nael Alian Introduction to PHP
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Ruby on Rails. What is Ruby? Programming Language Object-oriented Interpreted.
Introduction to Ruby WING Group Meeting 9 Jun 2006 Min-Yen Kan WING Group Meeting 9 Jun 2006 Min-Yen Kan.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
Smalltalk (and Squeak) Aida Dungan and Rick Shreve.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
+ Ruby and other programming Languages Ronald L. Ramos.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
JavaScript, Fourth Edition
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
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.
Jim Havrilla. Invoking Python Just type “python –m script.py [arg]” or “python –c command [arg]” To exit, quit() or Control-D is used To just use the.
Scripting with Ruby What is a scripting language? What is Ruby?
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Python 1 SIGCS 1 Intro to Python March 7, 2012 Presented by Pamela A Moore & Zenia C Bahorski 1.
12. MODULES Rocky K. C. Chang November 6, 2015 (Based on from Charles Dierbach. Introduction to Computer Science Using Python and William F. Punch and.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
BLOCK  is enclosed by curly brackets {}.  Keep in mind that blocks are always bounded by curly brackets, even if your block has only one code line.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Definition of the Programming Language CPRL
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.
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Pamela Moore & Zenia Bahorski
Java Primer 1: Types, Classes and Operators
Miscellaneous Items Loop control, block labels, unless/until, backwards syntax for “if” statements, split, join, substring, length, logical operators,
JavaScript Syntax and Semantics
JavaScript: Functions.
Chapter 14 Introduction to Ruby.
Python Primer 2: Functions and Control Flow
Introduction to Python
CIT 383: Administrative Scripting
Ruby Testing 2, 11/9/2004.
T. Jumana Abu Shmais – AOU - Riyadh
Learning Python 5th Edition
Presentation transcript:

Introduction to information systems RUBY dr inż. Tomasz Pieciukiewicz

Agenda  Ruby –general information  Syntax and semantics

Ruby  interpreted, dynamically typed programming language  created in 1995 by Yukihiro Matsumoto  became popular thanks to Ruby on Rails framework

Comments  Comments start with #  „broken” lines have to end with \ :puts\ "brokenline"  Commands don’t have to end with semicolon (or any other character)

Numbers  No limits on number size  _ may be used to separate groups of three digits from each other to increase readability: 12_345_678_901  Real numbers – „traditional” or expotential format: e-4

Strings  Strings – in " or ' puts "string in quotes" puts 'string in apostrophes'  Or using "%q syntax" puts %q!string! puts %Q{string} puts %

Strings  Multiline strings use <<TOKEN syntax print <<HERE I am a multiline string HERE

Variables  A variable is defined by value assignment text= "I am a string"  Variable names start with _ or a..z (but there are exceptions), may contain small and capital letters, digits and _.  Multi-word variable names use CamelCase: VariableNameInCamelCase

Expression interpolation  Interpolation of variables in quoted strings: "My name is #{name}"  Any expression may be put in #{…}

Symbols  Symbols are an equivalent for enumeration – after a fashion. Name of a symbol with colon in front: :ISP_address

Constants (sort of)  Constants names are written in caps: PI = 3.141_592_653  Their values may be redefined during program execution (but we'll get a warning ;) )

Arrays  Arrays are used and created like in other languages: array= [1,2,3,"I am", "an array"] puts array[0] array[0]=4  Negative array index – starting at the end of the table, counting backwards: puts array[-1]

Arrays  Processing multiple array elements – provide two values for index, first is the starting point, second– number of elements to be processed: array[3,2]="aaa"

Maps  Tables indexed using numbers, and/or strings or symbols: Map=/ {"Key"=>40,"Another"=>"value"} puts AsocArray["Key"]

Ranges  Range is defined using.. and … operators range= 1…4 #1,2,3 range= 1..4 #1,2,3,4 range= "a".."z"  Few useful methods:  to_a – convert range to an array  min – first element  max – last element

If if(cnd1) … elsif(cnd2) … else … end … if (cnd)

Unless unless(cnd) … else … end … unless (cnd)

Case case expression when v1 … when v2 … else … end

While and Until loops while(cnd) … end until(cnd) … end

Iterators  upto and downto – for equivalent, step 1 or -1: startingValue.upto(endValue) do |variable| … end 0.upto(array.length-1) do |loop_index| … end

Iterators  step – for with step different than 1 startValue.step(endValue, step) do \ |variable| … end 4.step(12,2) do |i| … end

Iterators  times – loop executed a specific number of times: howMany.times do … end 5.times do … end

Iterators  each–foreach once again collection.each do |variable| … end

Loops and iterators  Keywords that may be used in loops and iterators:  break – ends the loop  redo – redo the current iteration  next – move on to next iteration  retry – re-start the loop

Methods  method definition: def name(paramsList) … end def join (FirstWord, SecondWord) return FirstWord+" "+SecondWord end

Methods  Variable number of parameters –last defined argument preceded with * def join(FirstWord, *others) return FirstWord+" "+others.join(" ") end  Last parameter is treated like a table! If a table is to be passed as a parameter, its name should be preceded with *

Methods  Returning multiple values –separate values with commas, method returns an array: def RetArray return 1,2,3 end

Blocks  Section of code that may be passed to a method like a parameter  Blocks are enclosed in curly brackets or between do and end keywords  Blocks are invoked with the yield keyword

Blocks def greeting() yield end greeting {puts"Hello"}

Blocks  Blocks may be parametrized def greeting() yield "Hello" end greeting {|param| puts param}

BEGIN and END blocks  Code put in block marked as BEGIN is executed automatically after a program is loaded  Code put in block marked as END is executed automatically after a program finishes execution

Classes  Simplest class definition: class Name end  Class names ALWAYS start with a capital letter

Classes  initialize method–constructor class Name def initialize(parameters) … end

Classes  Instance and class attributes: – instance attributes  – class attributes  Attributes are usually initialized by the initialize method. Like variables –they are created by value assignment!

Classes  Object creation – using the new method, which invokes initialize()  instance= Name.new(parameters)

Classes  Getters/setters class Animal def color() end def color=(color) end

Classes  Auto-generated getters and setters: class Animal attr_reader:color attr_writer:color end  or class Animal attr_accessor:color end

Classes  Inheritance – operator < classDog < Animal … end  If necessary (usually), superclass constructor is invoked with super(parameters)

Classes  Access levels:  public  protected  private  Modifiers are used somewhere in the  class body, everything declared after  modifier has the new access level

Classes  class methods are defined by preceding the method name with class name: class Name def Name.method(parameters) … end

Modules  May be used to group classes and "independent" methods defined using the module keyword: module ModuleName  Imported using  include 'module.extension'  require 'module' (file extension has to be.rb)

Modules  Can't create module instances, so "independent" methods are usually class(or rather module) methods  Classes defined within module (like internal classes) are accessed with ModuleName::ClassName

Modules  Non-class independent methods may be imported into a class with include ModuleName  methods from many modules may be imported into a single class all will be treated as if they were defined within the class

Recommended Reading

 Programming Ruby 1.9 & 2.0 (4th edition): The Pragmatic Programmers' Guide, Dave Thomas, Chad Fowler, Andy Hunt  Metaprogramming Ruby 2: Program Like the Ruby Pros, Paolo Perrotta  Eloquent Ruby, Russ Olsen, Addison-Wesley 2011

Thank you for your attention