Ruby: An introduction - Who am I? Maciej Mensfeld Presented by: Maciej Mensfeld Ruby: An introduction dev.mensfeld.pl github.com/mensfeld.

Slides:



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

PHP I.
More about Ruby Maciej Mensfeld Presented by: Maciej Mensfeld More about Ruby dev.mensfeld.pl github.com/mensfeld.
Chapter 2.2 – More about Ruby Maciej Mensfeld Presented by: Maciej Mensfeld More about Ruby dev.mensfeld.pl github.com/mensfeld senior.
John Pinney Ruby in 20 minutes John Pinney
The Web Warrior Guide to Web Design Technologies
Chapter User authorization & safety Maciej Mensfeld Presented by: Maciej Mensfeld User authorization & safety dev.mensfeld.pl.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Information Technology Center Hany Abdelwahab Computer Specialist.
Scripting Languages CS351 – Programming Paradigms.
Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files.
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Unit 2: Java Introduction to Programming 2.1 Initial Example.
Introduction to Ruby CSE 413 Autumn 2008 Credit: Dan Grossman, CSE341.
Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction dev.mensfeld.pl github.com/mensfeld.
Ruby (on Rails) CSE 190M, Spring 2009 Week 1. The Players Kelly "Everyday I'm Hustlin' " Dunn Kim "Mouse" Todd Ryan "Papa T" Tucker.
The Ruby Programming Language
Introduction to Python Dr. Bernard Chen Ph.D. University of Central Arkansas July 9 th 2012
Hello AP Computer Science!. What are some of the things that you have used computers for?
CMSC 330: Organization of Programming Languages 1 Overview of Ruby.
Chapter 3.2 – RoR: easier, faster, better Maciej Mensfeld Presented by: Maciej Mensfeld RoR: easier, faster, better mensfeld.pl github.com/mensfeld.
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
An Introduction to Textual Programming
General Purpose Language Ruby Kit Chan COMP3351 Programming Languages November 9, 2007.
Chapter 8 High-Level Programming Languages (modified by Erin Chambers)
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
Chapter 4.1 – Deeper into Rails Maciej Mensfeld Presented by: Maciej Mensfeld Deeper into Rails mensfeld.pl github.com/mensfeld senior.
INTERNET APPLICATION DEVELOPMENT For More visit:
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
Nael Alian Introduction to PHP
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
PYTHON. Python is a high-level, interpreted, interactive and object- oriented scripting language. Python was designed to be highly readable which uses.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
The Java Programming Language
Ruby. Who am I? 1- Bunlong Van 2- Sreyleap Lay, 3- Chhon Meily Blog:
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
CSE 131 Computer Science 1 Module 1: (basics of Java)
Ruby on Rails. What is Ruby? Programming Language Object-oriented Interpreted.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 6 l Array Basics l Arrays and Methods l Programming with Arrays.
Trends in Scripting Languages History For me the purpose of life is partly to have joy. Programmers often feel joy when they can concentrate on the creative.
Smalltalk (and Squeak) Aida Dungan and Rick Shreve.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
Hello Computer Science!. Below is an example of a Hello World program in JAVA. While it is only three lines of code, there are many things that are happening.
Web applications – what & why? Maciej Mensfeld Presented by: Maciej Mensfeld Web applications – what & why? dev.mensfeld.pl github.com/mensfeld.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
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.
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.
Programmeren 1 6 september 2010 HOORCOLLEGE 2: INTERACTIE EN CONDITIES PROGRAMMEREN 1 6 SEPTEMBER 2009 Software Systems - Programming - Week.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 – Introduction to C# Programming Outline 3.1 Introduction 3.2 Simple Program: Printing a Line.
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
Introduction to information systems RUBY dr inż. Tomasz Pieciukiewicz.
Chapter 2 - OOP Maciej Mensfeld Presented by: Maciej Mensfeld More about OOP dev.mensfeld.pl github.com/mensfeld.
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.
Presented By P.SRIVIDYA 085D1A0552 Programming Language.
Development Environment
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.
Statements, Comments & Simple Arithmetic
Chapter 10 Programming Fundamentals with JavaScript
T. Jumana Abu Shmais – AOU - Riyadh
Loops CIS 40 – Introduction to Programming in Python
Introducing JavaScript
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Ruby: An introduction - Who am I? Maciej Mensfeld Presented by: Maciej Mensfeld Ruby: An introduction dev.mensfeld.pl github.com/mensfeld senior ruby senior ruby

Ruby: An introduction – please… Maciej Mensfeld Please… …ask me to slow down, if I speak to quickly; …ask me again, if I forget; …ask questions, if anything i say is not clear; …feel free to share your own observations Ruby: An introduction

Ruby: An introduction – What is Ruby? Maciej Mensfeld Ruby WT*? Ruby pictures

Ruby: An introduction – What is Ruby? Maciej Mensfeld What is Ruby? Ruby is like an Iron Man: Shiny; Red; Sometimes quite heavy; Powerfull; Needs electricity; (and you can use it with Lego Mindstorms)

Ruby: An introduction – What is Ruby? Maciej Mensfeld What is Ruby? Pure object-oriented programming language (even the number 1 is an instance of class); Created by Yukihiro Matsumoto in 1993; Freely available and open-source; Syntax is readable and easy to learn; Being used for text processing, web apps, general system administration, and AI and math research. Can be extended with Ruby or low-level C; Really helpful community;

What Ruby likes? Maciej Mensfeld What Ruby likes? Ruby likes to talk!

Who likes Ruby :-) Maciej Mensfeld Who likes to use Ruby?

What Ruby is NOT? Maciej Mensfeld What Ruby is not? Universal solution for lazy programmers; Universal solution in general; Ruby is not an Iron Man ;) Designed for small applications (with Rails in general); Python; Better PHP; Something that will work on Windows (don’t even thing about it!);

Ruby: An introduction – What is Ruby? Maciej Mensfeld Ruby community

A bit more about Ruby… Maciej Mensfeld Stay clean and nice!

Ruby: An introduction – What I love in Ruby? Maciej Mensfeld Clarity not ceremony – Main program Java: public class HelloWorld{ public static void main(String args){ System.out.println(„Hello World”); } Ruby: puts „Hello World”

Ruby: An introduction – What I love in Ruby? Maciej Mensfeld Expressive syntax && objects, objects, objects… 3.times { puts „Ruby is cool”} [„Maciek”, „John”, „Anna”].first #=> „Maciek” [„Maciek”, „John”, „Anna”].last #=> „Anna” attr_accessor :name „Anna”.class #=> String nil.class #=> NilClass 1.class #=> Integer {}.class #=> Hash [].class #=> Array self.class #=> Object (0..9).class #=> Range

Ruby: An introduction – syntax Maciej Mensfeld Ruby syntax – hello world as a function Hello World!puts „Hello World!” def h puts „Hello World!” end h => „Hello World!” Hello YourName! puts „Hello #{name}” def h(name=„World”) puts „Hello #{name}!” end h („Maciek”)=> „Hello Maciek!”

Ruby: An introduction – syntax Maciej Mensfeld Ruby syntax – classes, methods, objects Hello YourName! as an object # Comments starts with „#” class Messenger def initialize(name) # instance variables starts = name end public def hello puts „Hello }!” end msg = Message.new(„Maciek”) msg.hello #=> „Hello Maciek!”

Ruby: An introduction – syntax Maciej Mensfeld Ruby syntax – arrays, hashes (dictionaries) Arraysnames = [‘Maciek’, ‘John’, ‘Freddy’] names.length #=> 3 debts.length #=> 2 Hashesdebts={„Maciek”=>1, „John”=> 10}

Ruby: An introduction – syntax Maciej Mensfeld Ruby syntax – loops Ruby: friends.each{|friend| puts friend } C: for(i=0; i<number_of_elements;i++) { print element[i] } 10.times {|i| puts i } 10.downto(1){|i| puts i } There is no standard „for” loop in Ruby!

Ruby: An introduction – syntax Maciej Mensfeld Ruby craziness - symbols OMG symbols are so weird… When you ask someone : what are symbols in Ruby? Most programmers will say: they simple are! A symbol in Ruby is an instance of the class Symbol. A symbol is defined by prefixing a colon with an identifier. :name, :id, :user Symbols are most commonly used in creating hashes: h = {:name => "Jayson", : => The advantage in using symbols is the efficient use of memory. Maximum space taken by a symbol is never more than the space taken by an integer. This is because internally symbol is stored as an integer. In case of strings the memory space depends on the size of the string.

Ruby: An introduction – syntax Maciej Mensfeld Ruby craziness - symbols Also whenever a string is used in the program, a new instance is created. But for symbols, same identifier points to the same memory location! puts "name".object_id puts :name.object_id Compare: puts "name".object_id == "name".object_id puts :name.object_id == :name.object_id

Interactive Ruby Shell Maciej Mensfeld Interactive Ruby Shell Interactive Ruby Shell (IRB) is a shell for programming in the object-oriented scripting language Ruby. The program is launched from a command line and allows the execution of Ruby commands with immediate response, experimenting in real-time.

Interactive Ruby Shell Maciej Mensfeld Few simple examples Type something into IRB and get result of last evaluated expression Calculate!

Syntax basics Maciej Mensfeld Comments # Single line comments start with a „#” # You can always use them like this :-) # So you can have multiply comment lines # This approach is most common =begin This is a comment line it explains that the next line of code displays a welcome message =end

Syntax basics Maciej Mensfeld Reserved words BEGINdonextthen ENDelsenilltrue aliaselsifnotundef andendorunless beginensureredountil breakfalserescuewhen caseforretrywhile classifreturnwhile definself__FILE__ defined?modulesuper__LINE__ The following list shows the reserved words in Ruby. These reserved words may not be used as constant or variable names. They can, however, be used as method names.

Syntax basics Maciej Mensfeld Variables Global variables start with $ Local variables begin with a lowercase letter or _. The scope of a local variable ranges from class, module, def, or do to the corresponding end or from a block's opening brace to its close brace {}. There are also class and instance variables – but we will get there in next chapter

Syntax basics Maciej Mensfeld Variables When an uninitialized local variable is referenced, it is interpreted as a call to a method that has no arguments. Assignment to uninitialized local variables also serves as variable declaration. The variables start to exist until the end of the current scope is reached. The lifetime of local variables is determined when Ruby parses the program.

Syntax basics Maciej Mensfeld Pseudo-Variables They are special variables that have the appearance of local variables but behave like constants. You can not assign any value to these variables. self: The receiver object of the current method. true: Value representing true. false: Value representing false. nil: Value representing undefined. __FILE__: The name of the current source file. __LINE__: The current line number in the source file. Variables are coming…

Syntax basics Maciej Mensfeld Conditions - if if conditional [then] code... [elsif conditional [then] code...]... [else code...] end You can use if as a conditional modifier…

Syntax basics Maciej Mensfeld Conditions - unless unless conditional [then] code [else code ] end You can use unless as a conditional modifier…

Syntax basics Maciej Mensfeld Case statement case expression [when expression [, expression...] [then] code ]... [else code ] end

Syntax basics Maciej Mensfeld Loops

Syntax basics Maciej Mensfeld Loops

Syntax basics Maciej Mensfeld Loops „For” loop is a great idea but not in Ruby! (use it in PHP)

Syntax basics Maciej Mensfeld Strings

Syntax basics Maciej Mensfeld Strings Expression substitution is a means of embedding the value of any Ruby expression into a string using #{ and }:

Syntax basics Maciej Mensfeld Numbers

Syntax basics Maciej Mensfeld Numbers Numbers are instances of classes!

Ruby: An introduction Maciej Mensfeld THX Presented by: Maciej Mensfeld dev.mensfeld.pl github.com/mensfeld