Introduction to Ruby. Part I

Size: px
Start display at page:

Download "Introduction to Ruby. Part I"

Transcription

1 Introduction to Ruby Sebastian Fischer Part I Data Numbers, Strings, Ranges, Arrays/Hashes Control Branching, Loops, Iterators

2 Numbers >> 42 => 42 >> -17 => -17 >> 1.23 => 1.23 >> 4.56e7 => >> 2.34e-4 => >> 2.34>0 => true >> 17e-1.round => 2 >> 17/4 => 4 >> 17./ 4 => 4 Strings >> hello = "hello" => "hello" >> world = "world" => "world" >> hello = "#{hello} #{world}!" => "hello world!" >> hello.chop! => "hello world" >> hello => "hello world"

3 Escape >> "hello\nworld!" => "hello\nworld!" >> 'hello\nworld!' => "hello\\nworld!" >> "hello#{17+4}world!" => "hello21world!" >> 'hello#{17+4}world!' => "hello\#{17+4}world!" Regular Expressions >> hello =~ /\s\w+/ => 5 >> hello[5,6] => " world" >> hello[5..10] => " world" >> hello.gsub!(/\s\w+/,'\&!') => "hello world!" >> hello => "hello world!"

4 Ranges >> 1..3 => 1..3 >> (1..3).first => 1 >> (1..3).last => 3 >> (1..3).member? 3 => true >> (1..3).member? 4 => false >> (1..3).entries => [1, 2, 3] Arrays >> a = [1,true,"huh?"] => [1, true, "huh?"] >> a[2] => "huh?" >> a.length => 3 >> a + [42] => [1, true, "huh?", 42] >> a * 2 => [1, true, "huh?", 1, true, "huh?"]

5 Arrays >> (a*2)[2..4] => ["huh?", 1, true] >> (a*2)[2,3] => ["huh?", 1, true] >> a[-1] => "huh?" >> a[-2] => true Hashes >> h = { 1 => true, "huh?" => 2.34 } => {1=>true, "huh?"=>2.34} >> h[1] => true >> h["huh?"] => 2.34 >> h[true] => nil >> h[true] = 42 => 42 >> h => {true=>42, 1=>true, "huh?"=>2.34}

6 Symbols >> :foo => :foo >> :foo.to_i => >> :foo.id2name => "foo" >> "foo".to_sym => :foo Data Numbers Strings, Regular Expressions Ranges Arrays Hashes

7 If, Unless >> if 3>0 then 42 else 87 => 42 >> 42 if 3>0 => 42 >> unless 3>0 then 42 else 87 => 87 >> 87 unless 3>0 => nil Case >> case i >> when 1, 2..5 >> "one to five" >> when >> "six to ten" >> => "six to ten" >> case "abcdef" >> when "abc","def" >> "abc or def" >> when /def/ >> "includes def" >> => "includes def" >> (6..10) === 8 => true >> /def/ === "abcdef" => true

8 While >> fac5 = 1; n = 1 => 1 >> while n <= 5 >> fac5 = fac5 * n >> n = n+1 >> ; fac5 => 120 While while (<condition>) { label_redo: <body> label_next: } label_break:

9 Until >> fac5 = 1; n = 1 => 1 >> until n > 5 >> fac5 = fac5 * n >> n = n+1 >> ; fac5 => 120 For/in >> fac5 = 1; >> for n in 1..5 >> fac5 = fac5 * n >> ; fac5 => 120

10 Iterators >> fac5 = 1 => 1 >> (1..5).each { n fac5 = fac5 * n } => 1..5 >> fac5 => 120 Iterators >> "hello".each_byte { b puts b } => "hello" >> "hello\nworld!".each { l puts l } hello world! => "hello\nworld!"

11 Iterators >> (1..3).each{ n print n } 123=> 1..3 >> [1,2,3].each{ n print n } 123=> [1, 2, 3] >> h.each{ k,v puts "#{k} => #{v}" } true => 42 1 => true => {true=>42, 1=>true} Iterators >> 3.times { puts "hello" } hello hello hello => 3 >> 1.upto(3) do n?> puts n >> => 1

12 Control if, unless case while, until, for/in Iterators Part II Classes and Objects Inheritance, Methods, Access Control Accessor Methods Modules

13 Classes >> class Person >> def initialize name = name >> >> >> me = Person.new "Sebastian" => Classes class Man < Person def initialize name super = :male class Woman < Person def initialize name super = :female

14 Objects >> me = Man.new "Sebastian" >> me.@name SyntaxError: compile error >> me.name NoMethodError: undefined method `name' Accessor Methods class Person def def = n class Person attr_accessor :name

15 Accessor Methods >> me.name => "Sebastian" >> me.name = "Horst" => "Horst" >> me Modules module WithGer attr_reader :ger class Man include WithGer class Woman include WithGer

16 Reader Methods >> me.ger => :male >> me.ger = :female NoMethodError: undefined method `ger=' Singleton Methods >> def me.ger=(g) = g >> => nil >> me.ger = :female => :female >> me

17 Modules module Student = 0 attr_reader :nr def += 1 private :next_nr Mixin class MaleStudent < Man include Student def initialize name super = next_nr class FemaleStudent < Woman include Student...

18 Accessor Methods >> axel = MaleStudent.new "Axel" @ger=:male> >> rita = FemaleStudent.new "Rita" @ger=:female> >> axel.ger => :male >> rita.nr => 2 Exting Classes >> class Integer >> def fact >> return 1 if self==0 >> self * (self-1).fact >> >> => nil >> 5.fact => 120

19 Class Hierarchies >> 5.class => Fixnum >> Fixnum.superclass => Integer >> Integer.superclass => Numeric >> Numeric.superclass => Object >> Object.superclass => nil Classes are Objects >> Integer.class => Class >> Class.class => Class >> Class.superclass => Module >> Module.class => Class >> Module.superclass => Object

20 Global Functions >> def square x >> x*x >> => nil >> self.methods.select { m m =~ /sq/ } => ["square"] >> 42.methods.select { m m =~ /sq/ } => ["square"] >> "".square 7 => 49 Scope >> ["a","b","c"].each { str print str} abc=> ["a", "b", "c"] >> str NameError: undefined local variable or method `str' for main:object >> str = "z" => "z" >> ["a","b","c"].each { str print str} abc=> ["a", "b", "c"] >> str => "c"

21 Variables Constants uppercase: Math::PI Global Variables dollar sign: $PROGRAM_NAME Constants >> Object.constants => ["IO", "Student",...] >> Student.constants => [] >> WithGer.constants => []

22 Prettier Objects module Student def inspect str = "Student: #{nr}" str += ", Name: #{name}" \ if respond_to? :name str += ", Ger: #{ger}" \ if respond_to? :ger str Prettier Objects >> axel => Student: 1, Name: Axel, Ger: male >> puts axel #<MaleStudent:0x365470> => nil

23 Prettier Objects >> class Person >> def to_s; inspect >> >> puts axel Student: 1, Name: Axel, Ger: male => nil Exceptions class Person def name=(n) raise "name must not be empty!" \ if = n >> me.name = "" RuntimeError: name must not be empty!

24 Exceptions >> begin?> me.name = "" >> puts 'name was set to ""' >> rescue >> puts "could not set name" >> ensure?> puts "finished" >> could not set name finished => nil Useful Stuff >> 5.f 5.floor 5.freeze 5.frozen? 5.fact >> 5.f >> 5.methods => ["%", "inspect",...]

25 Useful Stuff $ ri Array#each Array#each array.each { item block } -> array Calls _block_ once for each element in _self_, passing that element as a parameter.... Ruby will teach you to express your ideas through a computer. You will be writing stories for a machine.

26 Part III Object#s Method#call Kernel#eval Object#s >> "hello world".s :length => 11 >> "hello world".s "length" => 11 >> "hello".s :<<, " world" => "hello world"

27 Method#call >> "hello world".method(:length).call => 11 >> app = "hello".method :<< => #<Method: String#<<> >> app.call(" world") => "hello world" Kernel#eval >> eval '"hello world".length' => 11 >> eval '"hello" << " world"' => "hello world" >> eval 'system "rm *"'

28 Module#class_eval class Module def my_attr_reader sym class_eval "def #{sym}()" << " def my_attr_writer sym class_eval "def #{sym}=(v)" << " Attribute Accessors class Klass my_attr_reader :a my_attr_reader :b my_attr_writer :b def

29 Attribute Accessors >> klass = Klass.new => >> klass.a => 42 >> klass.b = 17 => 17 >> klass.b => 17

Ruby, with foxes. Ruby, cont d. Warning. why's (poignant) Guide to Ruby

Ruby, with foxes. Ruby, cont d. Warning. why's (poignant) Guide to Ruby O Ruby, cont d n O Ruby, with foxes n why's (poignant) Guide to Ruby Ruby explained through humorous and more or less irrelevant stories about foxes, elfs, cats and others Warning If I was put off Ruby

More information

Programming Paradigms

Programming Paradigms PP 2016/17 Unit 4 Ruby Advanced 1/42 Programming Paradigms Unit 4 Ruby Advanced J. Gamper Free University of Bozen-Bolzano Faculty of Computer Science IDSE PP 2016/17 Unit 4 Ruby Advanced 2/42 Outline

More information

Ruby on Rails for PHP and Java Developers

Ruby on Rails for PHP and Java Developers Ruby on Rails for PHP and Java Developers Bearbeitet von Deepak Vohra 1. Auflage 2007. Taschenbuch. xvi, 394 S. Paperback ISBN 978 3 540 73144 3 Format (B x L): 15,5 x 23,5 cm Gewicht: 629 g Weitere Fachgebiete

More information

Ruby: Introduction, Basics

Ruby: Introduction, Basics Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 4 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie

More information

Iterators and blocks. Using iterators and blocks Iterate with each or use a for loop? Creating iterators

Iterators and blocks. Using iterators and blocks Iterate with each or use a for loop? Creating iterators Iterators and blocks Using iterators and blocks Iterate with each or use a for loop? Creating iterators CSc 372, Fall 2006 Ruby, Slide 77 Iterators and blocks Some methods are iterators. An iterator that

More information

Ruby: Introduction, Basics

Ruby: Introduction, Basics Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 3 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie

More information

Your First Ruby Script

Your First Ruby Script Learn Ruby in 50 pages Your First Ruby Script Step-By-Step Martin Miliauskas @mmiliauskas 1 Your First Ruby Script, Step-By-Step By Martin Miliauskas Published in 2013 by Martin Miliauskas On the web:

More information

Ruby: Introduction, Basics

Ruby: Introduction, Basics Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 4 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie

More information

Ruby: Object-Oriented Concepts

Ruby: Object-Oriented Concepts Ruby: Object-Oriented Concepts Computer Science and Engineering College of Engineering The Ohio State University Lecture 8 Classes Classes have methods and variables class LightBulb # name with CamelCase

More information

Ruby II. Classes. Classes are straight forward in Ruby.

Ruby II. Classes. Classes are straight forward in Ruby. Ruby II Classes Classes are straight forward in Ruby. expr Note that the class name begins with a capitol letter. Classes can contain instance variables, instance methods, class variables, class methods,

More information

Ruby. A Very Brief Introduction. Andreas Klappenecker

Ruby. A Very Brief Introduction. Andreas Klappenecker Ruby A Very Brief Introduction Andreas Klappenecker Ruby Ruby is a very popular open source interpreted programming language. Ruby combines object-oriented programming with concepts from functional programming

More information

CS 5142 Scripting Languages

CS 5142 Scripting Languages CS 5142 Scripting Languages 10/25/2012 Ruby 1 Outline Ruby Martin Hirzel 2 About Ruby Invented 1995 by Yokihiro Matz Matsumoto Influenced by SmallTalk Everything is an object (even e.g., integers) Blocks

More information

Ruby Topic Maps. Introduction to Ruby. Benjamin Bock.

Ruby Topic Maps. Introduction to Ruby. Benjamin Bock. Ruby Topic Maps http://rtm.rubyforge.org Introduction to Ruby Benjamin Bock 1 Calculator irb(main):001:0> 1+2 Type irb in your Terminal / Command / Shell window to start the interactive Ruby interpreter

More information

Ruby. An Introduction

Ruby. An Introduction Ruby An Introduction What is Ruby? Ruby is small and intuitive Ruby gives you immediate feedback Ruby is free Ruby is portable Ruby is object-oriented Ruby is a scripting (?) language Ruby supports regular

More information

Lecture 2. Object Orientation

Lecture 2. Object Orientation Lecture 2 Object Orientation 1 Homework 0 Grades Homework 0 grades were returned earlier this week Any questions? 2 Homework 1 Homework 1 is due tonight at 11:59pm You will be graded on: Correctness: 15

More information

Classes and Modules. Properties. Chapter 11

Classes and Modules. Properties. Chapter 11 Chapter 11 Classes and Modules In the previous chapters we have discussed the basics of the Ruby programming language, without looking at it from an object- oriented point of view. Object orientation is

More information

Ruby. Mooly Sagiv. Most slides taken from Dan Grossman

Ruby. Mooly Sagiv. Most slides taken from Dan Grossman Ruby Mooly Sagiv Most slides taken from Dan Grossman Ruby dynamic, reflective, object-oriented, general-purpose programming language Designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto

More information

SYMBOLS. you would not assign a value to a symbol: :name = "Fred" The Book of Ruby 2011 by Huw Collingbourne

SYMBOLS. you would not assign a value to a symbol: :name = Fred The Book of Ruby 2011 by Huw Collingbourne SYMBOLS Many newcomers to Ruby are confused by symbols. A symbol is an identifier whose first character is a colon (:), so :this is a symbol and so is :that. Symbols are, in fact, not at all complicated

More information

Lecture 2. Object Orientation 1 / 50

Lecture 2. Object Orientation 1 / 50 Lecture 2 Object Orientation 1 / 50 Homework 1 Homework 1 was due last night You will be graded on: Correctness: 15 points (passing all RSpec tests) Style: 5 points (having no Rubocop style offenses) Best

More information

Don t Repeat Yourself Repeat Others

Don t Repeat Yourself Repeat Others Don t Repeat Yourself Repeat Others RailsConf Baltimore, MD June 8, 2010 John Nunemaker Ordered List Why? Why? I am obsessed with improving Why? I am obsessed with improving I have learned a lot of late

More information

Lecture 2. Object Orientation 1 / 51

Lecture 2. Object Orientation 1 / 51 Lecture 2 Object Orientation 1 / 51 Homework 1 Homework 1 was due at noon You will be graded on: Correctness: 15 points (passing all RSpec tests) Style: 5 points (having no Rubocop style offenses) Best

More information

Ruby logistics. CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Ruby: Not our focus. Ruby: Our focus. A note on the homework

Ruby logistics. CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Ruby: Not our focus. Ruby: Our focus. A note on the homework Ruby logistics CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP Dan Grossman Autumn 2018 Next two sections use the Ruby language http://www.ruby-lang.org/ Installation / basic usage

More information

One can evaluate any valid string as code at run time using eval.

One can evaluate any valid string as code at run time using eval. Metaprogramming Metaprogramming means writing code that writes code. This allows us to modify the behavior of a program at run time. Ruby has several metaprogramming facilities. One can add create a new

More information

15.1 Origins and Uses of Ruby

15.1 Origins and Uses of Ruby 15.1 Origins and Uses of Ruby - Designed by Yukihiro Matsumoto; released in 1996 - Use spread rapidly in Japan - Use is now growing in part because of its use in Rails - A pure object-oriented purely interpreted

More information

Classes and Objects in Ruby

Classes and Objects in Ruby Computer Science and Engineering IIT Bombay kuhoo@cse.iitb.ac.in Nov 29, 2004 Classes and Objects Rubby Object A set of flags, instance variables and an associated class Rubby Class An object of class

More information

Strings and Variables

Strings and Variables Strings and Variables class Player attr_accessor :name attr_reader :health def initialize(name, health=100) @name = name.capitalize @health = health @found_treasures = Hash.new(0) Inside the initialize

More information

CSc 372 Comparative Programming Languages

CSc 372 Comparative Programming Languages CSc 372 Comparative Programming Languages 26 : Ruby Classes Christian Collberg collberg+372@gmail.com Department of Computer Science University of Arizona Copyright c 2008 Christian Collberg [1] Inheritance

More information

CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Dan Grossman Winter 2013

CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Dan Grossman Winter 2013 CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP Dan Grossman Winter 2013 Ruby logistics Next two sections use the Ruby language http://www.ruby-lang.org/ Installation / basic usage

More information

What is Ruby? CSc 372. Comparative Programming Languages. 27 : Ruby Introduction. Department of Computer Science University of Arizona

What is Ruby? CSc 372. Comparative Programming Languages. 27 : Ruby Introduction. Department of Computer Science University of Arizona What is Ruby? CSc 372 Comparative Programming Languages 27 : Ruby Introduction Department of Computer Science University of Arizona Everything is an object. Everything can be changed: method can be added

More information

Alleviate the Apprehension of Coding in Ruby

Alleviate the Apprehension of Coding in Ruby Alleviate the Apprehension of Coding in Ruby Chris Lasell Apple Peeler Pixar Animation Studios Install session materials Includes some example code & libraries ruby-jss and ruby gem dependencies into /Library/Ruby/Gems

More information

Introduction CMSC 330: Organization of Programming Languages. Books on Ruby. Applications of Scripting Languages

Introduction CMSC 330: Organization of Programming Languages. Books on Ruby. Applications of Scripting Languages Introduction CMSC 330: Organization of Programming Languages Ruby is an object-oriented, imperative scripting language I wanted a scripting language that was more powerful than Perl, and more object-oriented

More information

INTRODUCTION TO RUBY PETER COOPER

INTRODUCTION TO RUBY PETER COOPER INTRODUCTION TO RUBY PETER COOPER If you get bored... www.petercooper.co.uk www.rubyinside.com www.ruby-lang.org THE ANECDOTE THE DOWNSIDES THE LANGUAGE THE COMMUNITY THE LIBRARIES THE APPLICATIONS THE

More information

Metaprogramming in Ruby A Pattern Catalog

Metaprogramming in Ruby A Pattern Catalog Metaprogramming in Ruby A Pattern Catalog Sebastian Günther, Marco Fischer School of Computer Science, University of Magdeburg Abstract Modern programming languages provide extensive metaprogramming facilities.

More information

CSE 413 Programming Languages & Implementation. Hal Perkins Winter 2019 Ruby Containers, Blocks, and Procs

CSE 413 Programming Languages & Implementation. Hal Perkins Winter 2019 Ruby Containers, Blocks, and Procs CSE 413 Programming Languages & Implementation Hal Perkins Winter 2019 Ruby Containers, Blocks, and Procs CSE413 Winter 2019 1 The Plan Ruby container data structures Blocks and control structures (iterators,

More information

CSC 372 Ruby Mid-term Exam April 11, 2014

CSC 372 Ruby Mid-term Exam April 11, 2014 Last name, NetID CSC 372 Ruby Mid-term Exam April 11, 2014 READ THIS FIRST Read this page now but do not turn this page until you are told to do so. Go ahead and fill in your last name and NetID in the

More information

MTAT Agile Software Development in the Cloud. Lecture 3: Ruby (cont.)

MTAT Agile Software Development in the Cloud. Lecture 3: Ruby (cont.) MTAT.03.295 Agile Software Development in the Cloud Lecture 3: Ruby (cont.) Luciano García-Bañuelos University of Tartu Let s play with our example tree1 = BinaryTree.new(10) tree1.insert(5) tree1.insert(15)

More information

Let s Write an Interpreter!

Let s Write an Interpreter! Let s Write an Interpreter! Thank you so much! Setting Expectations TODO 168 Slides in 30 minutes. ~5.6 spm. Boatloads of content. Almost all code. I hope to Hurt Brains. How to solve a rubiks cube in

More information

Active Model Basics. December 29, 2014

Active Model Basics. December 29, 2014 Active Model Basics December 29, 2014 This guide should provide you with all you need to get started using model classes. Active Model allows for Action Pack helpers to interact with plain Ruby objects.

More information

CSE341: Programming Languages Lecture 23 Multiple Inheritance, Mixins, Interfaces, Abstract Methods. Dan Grossman Autumn 2018

CSE341: Programming Languages Lecture 23 Multiple Inheritance, Mixins, Interfaces, Abstract Methods. Dan Grossman Autumn 2018 CSE341: Programming Languages Lecture 23 Multiple Inheritance, Mixins, Interfaces, Abstract Methods Dan Grossman Autumn 2018 What next? Have used classes for OOP's essence: inheritance, overriding, dynamic

More information

Programming Paradigms Written Exam (6 CPs)

Programming Paradigms Written Exam (6 CPs) Programming Paradigms Written Exam (6 CPs) 22.06.2017 First name Student number Last name Signature Instructions for Students Write your name and student number on the exam sheet and on every solution

More information

In fact, as your program grows, you might imagine it organized by class and superclass, creating a kind of giant tree structure. At the base is the

In fact, as your program grows, you might imagine it organized by class and superclass, creating a kind of giant tree structure. At the base is the 6 Method Lookup and Constant Lookup As we saw in Chapter 5, classes play an important role in Ruby, holding method definitions and constant values, among other things. We also learned how Ruby implements

More information

RUBY OPERATORS. Ruby Arithmetic Operators: Ruby Comparison Operators:

RUBY OPERATORS. Ruby Arithmetic Operators: Ruby Comparison Operators: http://www.tutorialspoint.com/ruby/ruby_operators.htm RUBY OPERATORS Copyright tutorialspoint.com Ruby supports a rich set of operators, as you'd expect from a modern language. Most operators are actually

More information

CSE 341, Autumn 2015, Ruby Introduction Summary

CSE 341, Autumn 2015, Ruby Introduction Summary CSE 341, Autumn 2015, Ruby Introduction Summary Disclaimer: This lecture summary is not necessarily a complete substitute for atting class, reading the associated code, etc. It is designed to be a useful

More information

Introduction to Ruby, part I

Introduction to Ruby, part I Introduction to Ruby, part I April 20, 205 Output # evaluate expression and prints result. >> 4 + 5 => 9 >> 7 * 3 => 2 >> Hello, world! => "Hello, world!" # print text on standard output >> puts Hello,

More information

Immutability and Design Patterns in Ruby

Immutability and Design Patterns in Ruby Immutability and Design Patterns in Ruby Seamus Brady, seamus@corvideon.ie 28/03/2013 Abstract Functional Programming has seen a resurgence in interest in the last few years and is often mentioned in opposition

More information

Ruby on Rails TKK, Otto Hilska

Ruby on Rails TKK, Otto Hilska Ruby on Rails intro @ TKK, 25.5.2009 Otto Hilska 1 Today s agenda 1. The Ruby programming language 2. Ruby on Rails framework 3. An example project 2 About me Started Nodeta Oy in 2004 10+ employees always

More information

Project 6 Due 11:59:59pm Thu, Dec 10, 2015

Project 6 Due 11:59:59pm Thu, Dec 10, 2015 Project 6 Due 11:59:59pm Thu, Dec 10, 2015 Updates None yet. Introduction In this project, you will add a static type checking system to the Rube programming language. Recall the formal syntax for Rube

More information

Project 5 Due 11:59:59pm Wed, July 16, 2014

Project 5 Due 11:59:59pm Wed, July 16, 2014 Project 5 Due 11:59:59pm Wed, July 16, 2014 Updates Apr 1. Clarified that built-in methods can t be overridden, and that the evaluation order for send is slightly different than normal method call. Mar

More information

Ruby: Objects and Dynamic Types

Ruby: Objects and Dynamic Types Ruby: Objects and Dynamic Types Computer Science and Engineering College of Engineering The Ohio State University Lecture 5 Primitive vs Reference Types Recall Java type dichotomy: Primitive: int, float,

More information

Programming Paradigms Written Exam (6 CPs)

Programming Paradigms Written Exam (6 CPs) Programming Paradigms Written Exam (6 CPs) 19.09.2018 First name Student number Last name Signature Instructions for Students Write your name and student number on the exam sheet and on every solution

More information

Project 5 Due 11:59:59pm Wed, Nov 25, 2015 (no late submissions)

Project 5 Due 11:59:59pm Wed, Nov 25, 2015 (no late submissions) Introduction Project 5 Due 11:59:59pm Wed, Nov 25, 2015 (no late submissions) In this project, you will write a compiler for a programming language called Rube, which is a small objectoriented programming

More information

Python 1: Intro! Max Dougherty Andrew Schmitt

Python 1: Intro! Max Dougherty Andrew Schmitt Python 1: Intro! Max Dougherty Andrew Schmitt Computational Thinking Two factors of programming: The conceptual solution to a problem. Solution syntax in a programming language BJC tries to isolate and

More information

Hidden gems in Ruby on Rails

Hidden gems in Ruby on Rails Hidden gems in Ruby on Rails Prem Sichanugrist!! @sikachu /sikachu *57600x speed *57600x speed Flight attendance (Can speak Chinese) Flight attendance (Can speak Chinese) Me (Thai) Flight attendance

More information

Metaprogramming in Ruby A Pattern Catalog

Metaprogramming in Ruby A Pattern Catalog Metaprogramming in Ruby A Pattern Catalog Sebastian Günther, School of Computer Science, University of Magdeburg and Marco Fischer, School of Computer Science, University of Magdeburg Modern programming

More information

Introduction. CSC 440: Software Engineering Slide #1

Introduction. CSC 440: Software Engineering Slide #1 Introduction CSC 440: Software Engineering Slide #1 Topics 1. Course Goals 2. Programming: Small vs. Large 3. Challenges of Large Programs 4. Software Processes and Methods 5. Teams and Roles 6. Rails

More information

A Tour of Ruby.... for Java programmers

A Tour of Ruby.... for Java programmers A Tour of Ruby... for Java programmers Everything has a value Everything has a value, which I'll show in a comment (following Matsumoto): 1234 # => 1234 2 + 2 # => 4 'Hello' + 'World' # => 'HelloWorld'

More information

Programming Languages

Programming Languages Programming Languages Dr. Michael Petter WS 2016/17 Exercise Sheet 8 Assignment 8.1 Quiz 1. Can Smalltalk Inheritance be used to model Java s inheritance? What about attribute access? 2. In a Trait-based

More information

iflame INSTITUTE OF TECHNOLOGY

iflame INSTITUTE OF TECHNOLOGY Web Development Ruby On Rails Duration: 3.5 Month Course Overview Ruby On Rails 4.0 Training From Iflame Allows You To Build Full Featured, High Quality, Object Oriented Web Apps. Ruby On Rails Is A Full

More information

Introduction to: Computers & Programming: Review prior to 1 st Midterm

Introduction to: Computers & Programming: Review prior to 1 st Midterm Introduction to: Computers & Programming: Review prior to 1 st Midterm Adam Meyers New York University Summary Some Procedural Matters Summary of what you need to Know For the Test and To Go Further in

More information

CSE341: Programming Languages Spring 2017 Unit 7 Summary Dan Grossman, University of Washington

CSE341: Programming Languages Spring 2017 Unit 7 Summary Dan Grossman, University of Washington CSE341: Programming Languages Spring 2017 Unit 7 Summary Dan Grossman, University of Washington Standard Description: This summary covers roughly the same material as class and recitation section. It can

More information

file:///users/dave/tmp/rubyadv/html/metaprogramming.html

file:///users/dave/tmp/rubyadv/html/metaprogramming.html Page 1 of 13 Metaprogramming Object state behavior Me, Me, Me First, understand self self self is the current object Default receiver for method calls with no receiver Place where instance variables are

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

INDEX. Symbols & Numbers

INDEX. Symbols & Numbers INDEX Symbols & Numbers & (ampersand), 166, 167 && (and operator), 85, 93 * (asterisk), 251 252, 260 *?, 260 @ (at sign), 23, 100 @@ (class variables), 23, 100 \ (line continuation character), 297 \B,

More information

Project 5 Due 11:59:59pm Tuesday, April 25, 2017

Project 5 Due 11:59:59pm Tuesday, April 25, 2017 Project 5 Due 11:59:59pm Tuesday, April 25, 2017 Introduction In this project, you will write a compiler for a programming language called Rube, which is a small objectoriented programming language with

More information

Solutions for CSC 372 Ruby Mid-term Exam April 11, 2014

Solutions for CSC 372 Ruby Mid-term Exam April 11, 2014 Problem 1: (21 points) Mean and median: 17.6, 19 Solutions for CSC 372 Ruby Mid-term Exam April 11, 2014 In this problem you are to write a Ruby program tail.rb that prints the last N lines of standard

More information

CMSC330 Spring 2015 Midterm #1 9:30am/11:00am/12:30pm

CMSC330 Spring 2015 Midterm #1 9:30am/11:00am/12:30pm CMSC330 Spring 2015 Midterm #1 9:30am/11:00am/12:30pm Name: Discussion Time (circle one): 10am 11am 12pm 1pm 2pm 3pm Discussion TA (circle one): Amelia Casey Chris Mike Elizabeth Eric Tommy Instructions

More information

Python I. Some material adapted from Upenn cmpe391 slides and other sources

Python I. Some material adapted from Upenn cmpe391 slides and other sources Python I Some material adapted from Upenn cmpe391 slides and other sources Overview Names & Assignment Data types Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics

More information

Quiz Stuff. Use a full sheet of 8½x11" paper. (Half sheet? Half credit!) ...

Quiz Stuff. Use a full sheet of 8½x11 paper. (Half sheet? Half credit!) ... QUIZ! Quiz Stuff Use a full sheet of 8½x11" paper. (Half sheet? Half credit!) Put your last name and first initial in the far upper left hand corner of the paper, where a staple would hit it. (It helps

More information

Welcome to Ruby. Yehuda Katz. Engine Yard

Welcome to Ruby. Yehuda Katz. Engine Yard Welcome to Ruby Yehuda Katz Engine Yard 1 Getting Started > Install JRuby > Add JRuby to Your Path > Start jirb 2 2 Everything is an Object > Numbers 8, 8.0, 0x8, 010, 0b1000 > Boolean true, false > Null

More information

Trolls of Ryan Davis, Seattle.rb. Trolls of MWRC 2013, Salt Lake City, UT

Trolls of Ryan Davis, Seattle.rb. Trolls of MWRC 2013, Salt Lake City, UT Trolls of 2013 Trolls of 2013 Trolls of 2013 Setting Expectations Followup of my talk, Occupy Ruby: Why We Need to Moderate the 1% 130 Slides in 30 minutes. 4.3 spm I must go quickly, so please hold questions.

More information

Today: Revisit some objects. Programming Languages. Key data structure: Dictionaries. Using Dictionaries. CSE 130 : Winter 2009

Today: Revisit some objects. Programming Languages. Key data structure: Dictionaries. Using Dictionaries. CSE 130 : Winter 2009 CSE 130 : Winter 2009 Programming Languages Lecture 11: What s in a Name? Today: Revisit some objects Exploit features and build powerful expressions Base: int, float, complex Sequence: string, tuple,

More information

Programming Languages

Programming Languages CSE 130 : Spring 2011 Programming Languages Lecture 13: What s in a Name? Ranjit Jhala UC San Diego Next: What s in a name? More precisely: How should programmer think of data What does a variable x really

More information

About Ruby Comments Constants and variables Scopes Methods Ranges Arrays Operators Flow Control Iterators Math Library Date and Time Hashes Object

About Ruby Comments Constants and variables Scopes Methods Ranges Arrays Operators Flow Control Iterators Math Library Date and Time Hashes Object October 14,2014 About Ruby Comments Constants and variables Scopes Methods Ranges Arrays Operators Flow Control Iterators Math Library Date and Time Hashes Object and Classes Conclusion Hmw 2 created by

More information

Lesson 10B Class Design. By John B. Owen All rights reserved 2011, revised 2014

Lesson 10B Class Design. By John B. Owen All rights reserved 2011, revised 2014 Lesson 10B Class Design By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Encapsulation Inheritance and Composition is a vs has a Polymorphism Information Hiding Public

More information

Next: What s in a name? Programming Languages. Data model in functional PL. What s in a name? CSE 130 : Fall Lecture 13: What s in a Name?

Next: What s in a name? Programming Languages. Data model in functional PL. What s in a name? CSE 130 : Fall Lecture 13: What s in a Name? Next: What s in a name? CSE 13 : Fall 211 Programming Languages Lecture 13: What s in a Name? More precisely: How should programmer think of data What does a variable x really mean? Ranjit Jhala UC San

More information

Beyond Blocks: Python Session #1

Beyond Blocks: Python Session #1 Beyond Blocks: Session #1 CS10 Spring 2013 Thursday, April 30, 2013 Michael Ball Beyond Blocks : : Session #1 by Michael Ball adapted from Glenn Sugden is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike

More information

PYTHON FOR KIDS A Pl ayfu l I ntrodu ctio n to Prog r am m i ng J a s o n R. B r i g g s

PYTHON FOR KIDS A Pl ayfu l I ntrodu ctio n to Prog r am m i ng J a s o n R. B r i g g s PYTHON FO R K I D S A P l ay f u l I n t r o d u c t i o n to P r o g r a m m i n g Jason R. Briggs Index Symbols and Numbers + (addition operator), 17 \ (backslash) to separate lines of code, 235 in strings,

More information

Common Lisp. Blake McBride

Common Lisp. Blake McBride Contents Common Lisp Blake McBride (blake@mcbride.name) 1 Data Types 2 2 Numeric Hierarchy 3 3 Comments 3 4 List Operations 4 5 Evaluation and Quotes 5 6 String Operations 5 7 Predicates 6 8 Math Predicates

More information

CSC 1351 The Twelve Hour Exam From Hell

CSC 1351 The Twelve Hour Exam From Hell CSC 1351 The Twelve Hour Exam From Hell Name: 1 Arrays (Ch. 6) 1.1 public class L { int [] data ; void append ( int n) { int [] newdata = new int [ data. length +1]; for ( int i =0;i< data. length ;i ++)

More information

Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7

Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7 Scheme Textbook, Sections 13.1 13.3, 13.7 1 Functional Programming Based on mathematical functions Take argument, return value Only function call, no assignment Functions are first-class values E.g., functions

More information

Lecture 1. Basic Ruby 1 / 61

Lecture 1. Basic Ruby 1 / 61 Lecture 1 Basic Ruby 1 / 61 What does this do? 3.times do print 'Hello, world!' end 2 / 61 Why Ruby? Optimized for programmer happiness Used for Ruby on Rails Very popular web framework 3 / 61 Course Policies

More information

CMSC330 Spring 2015 Midterm #1 9:30am/11:00am/12:30pm

CMSC330 Spring 2015 Midterm #1 9:30am/11:00am/12:30pm CMSC330 Spring 2015 Midterm #1 9:30am/11:00am/12:30pm Name: Discussion Time (circle one): 10am 11am 12pm 1pm 2pm 3pm Discussion TA (circle one): Amelia Casey Chris Mike Elizabeth Eric Tommy Instructions

More information

Unifying Fixnum and Bignum into Integer. Tanaka National Institute of Advanced Industrial Science and Technology (AIST)

Unifying Fixnum and Bignum into Integer. Tanaka National Institute of Advanced Industrial Science and Technology (AIST) Unifying Fixnum and Bignum into Integer Tanaka Akira @tanaka_akr 2016-09-08 National Institute of Advanced Industrial Science and Technology (AIST) Announcement Ruby 2.4 unify Fixnum and Bignum into Integer

More information

Improving Coverage Analysis

Improving Coverage Analysis Improving Coverage Analysis 1 Ryan Davis Coding professionally 25 years, 16 years Ruby Founder, Seattle.rb; First & Oldest Ruby Brigade Author: minitest, flog, flay, debride, ruby_parser, etc. ~114 million

More information

CSC/ECE 517: Object-Oriented Languages and Systems Summer 2008 Test 1 with Answers

CSC/ECE 517: Object-Oriented Languages and Systems Summer 2008 Test 1 with Answers CSC/ECE 517: Object-Oriented Languages and Systems Summer 2008 Test 1 with Answers This was a 95-minute open-book test. There were a total of 102 points on this test. If you answered more than 100% worth

More information

The Interpreter + Calling Functions. Scheme was designed by people. The Interpreter + Calling Functions. Clickers. Parentheses Matter We asked scheme

The Interpreter + Calling Functions. Scheme was designed by people. The Interpreter + Calling Functions. Clickers. Parentheses Matter We asked scheme The Interpreter + Calling Functions 3 3 Why not 3 + 4 (+ 3 4) 7 (+ 3 4 5 6) 8 Here we were calling the function + The Interpreter + Calling Functions 4 (+ 3 (sqrt 6)) 7 (+ 3 4 5 6) 8 (sqrt 6) Not all procedures

More information

MTAT Agile Software Development in the Cloud Lecture 4: More on Ruby

MTAT Agile Software Development in the Cloud Lecture 4: More on Ruby MTAT.03.295 Agile Software Development in the Cloud Lecture 4: More on Ruby Luciano García-Bañuelos University of Tartu Regular Expressions Widely use tool for specifying (and implemen5ng) pa7ern matching

More information

Intro to Ruby Scripting

Intro to Ruby Scripting Intro to Ruby Scripting http://phys.lsu.edu/~galanakis/resources/ruby_talk.pdf Dimitrios Galanakis Thursday April 15th A Tutorial for the LSU Center for Computation and Technology Why Scripting? Advantages

More information

The Typed Racket Guide

The Typed Racket Guide The Typed Racket Guide Version 5.3.6 Sam Tobin-Hochstadt and Vincent St-Amour August 9, 2013 Typed Racket is a family of languages, each of which enforce

More information

Common LISP Tutorial 1 (Basic)

Common LISP Tutorial 1 (Basic) Common LISP Tutorial 1 (Basic) CLISP Download https://sourceforge.net/projects/clisp/ IPPL Course Materials (UST sir only) Download https://silp.iiita.ac.in/wordpress/?page_id=494 Introduction Lisp (1958)

More information

CSE : Python Programming

CSE : Python Programming CSE 399-004: Python Programming Lecture 2: Data, Classes, and Modules January 22, 2007 http://www.seas.upenn.edu/~cse39904/ Administrative things Teaching assistant Brian Summa (bsumma @ seas.upenn.edu)

More information

String Computation Program

String Computation Program String Computation Program Reference Manual Scott Pender scp2135@columbia.edu COMS4115 Fall 2012 10/31/2012 1 Lexical Conventions There are four kinds of tokens: identifiers, keywords, expression operators,

More information

CMSC330 Fall 2014 Midterm 1 Grading

CMSC330 Fall 2014 Midterm 1 Grading CMSC330 Fall 2014 Midterm 1 Grading 1. (8 pts) Programming languages (PL) et al. For the following multiple choice questions, circle the letter(s) on the right corresponding to the best answer(s) to each

More information

Inheritance in Ruby. You are familiar with the idea of inheritance and how to use this in programming.

Inheritance in Ruby. You are familiar with the idea of inheritance and how to use this in programming. Inheritance in Ruby You are familiar with the idea of inheritance and how to use this in programming. In this introduction, I'll describe inheritance in Ruby from scratch. Much of this material should

More information

Crash Course in Ruby. Summer Institute 2018

Crash Course in Ruby. Summer Institute 2018 Crash Course in Ruby Summer Institute 2018 Data Types in Ruby Integers my_int = -25 # -25 large_number = 1_000_000 # 1000000 Floats my_float = 17.2 # 17.2 sum = 16 + 14.0 # 30.0 Boolean result = 6 > 10

More information

COMP519 Web Programming Lecture 21: Python (Part 5) Handouts

COMP519 Web Programming Lecture 21: Python (Part 5) Handouts COMP519 Web Programming Lecture 21: Python (Part 5) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Functions

More information

Adding Static Typing to Ruby

Adding Static Typing to Ruby Adding Static Typing to Ruby Jeff Foster University of Maryland, College Park Joint work with Mike Furr, David An, and Mike Hicks Introduction Scripting languages are extremely popular Lang Rating Lang

More information

Python for Non-programmers

Python for Non-programmers Python for Non-programmers A Gentle Introduction 1 Yann Tambouret Scientific Computing and Visualization Information Services & Technology Boston University 111 Cummington St. yannpaul@bu.edu Winter 2013

More information

Programming Languages

Programming Languages TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Programming Languages Mixins Dr. Michael Petter Winter 2014 Mixins 1 / 30 What advanced techiques are there besides multiple implementation inheritance?

More information