More about Ruby Maciej Mensfeld Presented by: Maciej Mensfeld More about Ruby dev.mensfeld.pl github.com/mensfeld.

Slides:



Advertisements
Similar presentations
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
Advertisements

Chapter 2.2 – More about Ruby Maciej Mensfeld Presented by: Maciej Mensfeld More about Ruby dev.mensfeld.pl github.com/mensfeld senior.
A Crash Course Python. Python? Isn’t that a snake? Yes, but it is also a...
1 Lecture 11 Interfaces and Exception Handling from Chapters 9 and 10.
Language of the Month If it’s December, it must be Ruby! Adam Coffman and Brent Beer.
Computer Science 1620 Loops.
Names and Scopes CS 351. Program Binding We should be familiar with this notion. A variable is bound to a method or current block e.g in C++: namespace.
Scripting Languages For Virtual Worlds. Outline Necessary Features Classes, Prototypes, and Mixins Static vs. Dynamic Typing Concurrency Versioning Distribution.
Introduction to Python
Guide To UNIX Using Linux Third Edition
Chapter 3 Planning Your Solution
C++ fundamentals.
Introduction to Methods
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
JS Arrays, Functions, Events Week 5 INFM 603. Agenda Arrays Functions Event-Driven Programming.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
Lecture Note 3: ASP Syntax.  ASP Syntax  ASP Syntax ASP Code is Browser-Independent. You cannot view the ASP source code by selecting "View source"
June 14, 2001Exception Handling in Java1 Richard S. Huntrods June 14, 2001 University of Calgary.
Object Oriented Programming
And other languages…. must remember to check return value OR, must pass label/exception handler to every function Caller Function return status Caller.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
Introduction to Python
CMSC 202 Exceptions. Aug 7, Error Handling In the ideal world, all errors would occur when your code is compiled. That won’t happen. Errors which.
Introduction to Python 2 Dr. Bernard Chen University of Central Arkansas PyArkansas 2011.
Python: Classes By Matt Wufsus. Scopes and Namespaces A namespace is a mapping from names to objects. ◦Examples: the set of built-in names, such as the.
Goodbye rows and tables, hello documents and collections.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Errors And How to Handle Them. GIGO There is a saying in computer science: “Garbage in, garbage out.” Is this true, or is it just an excuse for bad programming?
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Python – Part 1 Python Programming Language 1. What is Python? High-level language Interpreted – easy to test and use interactively Object-oriented Open-source.
Functions, Procedures, and Abstraction Dr. José M. Reyes Álamo.
Objects & Dynamic Dispatch CSE 413 Autumn Plan We’ve learned a great deal about functional and object-oriented programming Now,  Look at semantics.
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
Python Functions.
1 CS161 Introduction to Computer Science Topic #9.
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
M1G Introduction to Programming 2 5. Completing the program.
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.
CSC 1010 Programming for All Lecture 4 Loops Some material based on material from Marty Stepp, Instructor, University of Washington.
Exception-Handling Fundamentals  A Java exception is an object that describes an exceptional (that is, error) condition that has occurred in a piece of.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
IS2802 Introduction to Multimedia Applications for Business Lecture 4: JavaScript, Loops, and Conditional Statements Rob Gleasure
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
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.
JavaScript and Ajax (Control Structures) Week 4 Web site:
Lecture10 Exception Handling Jaeki Song. Introduction Categories of errors –Compilation error The rules of language have not been followed –Runtime error.
OOP Basics Classes & Methods (c) IDMS/SQL News
Distributed Computing & Embedded Systems Chapter 4: Remote Method Invocation Dr. Umair Ali Khan.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Presented By P.SRIVIDYA 085D1A0552 Programming Language.
similar concepts, different syntax
Data Virtualization Tutorial: Introduction to SQL Script
Topics Introduction to Repetition Structures
Introduction to PL/SQL
Variables, Expressions, and IO
Introduction to Python
Python Primer 2: Functions and Control Flow
Topics Introduction to File Input and Output
Introduction to Python
Packages and Interfaces
Problems Debugging is fine and dandy, but remember we divided problems into compile-time problems and runtime problems? Debugging only copes with the former.
CISC101 Reminders All assignments are now posted.
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
Python While Loops.
Topics Introduction to File Input and Output
CMSC 202 Exceptions.
Exception Handling.
Presentation transcript:

More about Ruby Maciej Mensfeld Presented by: Maciej Mensfeld More about Ruby dev.mensfeld.pl github.com/mensfeld

More about Ruby Maciej Mensfeld Exceptions Ruby provide a nice mechanism to handle exceptions. We enclose the code that could raise an exception in a begin/end block and use rescue clauses to tell Ruby the types of exceptions we want to handle.

More about Ruby Maciej Mensfeld Exceptions Using retry statement

More about Ruby Maciej Mensfeld Exceptions The following is the flow of the process: 1.an exception occurred at open 2.went to rescue 3.fname was re-assigned 4.by retry went to the beginning of the begin 5.this time file opens successfully 6.continued the essential process Notice that if the file of re-substituted name does not exist this example code retries infinitely. Be careful if you use retry for an exception process.

More about Ruby Maciej Mensfeld Exceptions - raise You can use raise statement to raise an exception. The following method raises an exception whenever it's called. It's second message will be printed.

More about Ruby Maciej Mensfeld Exceptions - ensure Ensure goes after the last rescue clause and contains a chunk of code that will always be executed as the block terminates. It doesn't matter if the block exits normally, if it raises and rescues an exception, or if it is terminated by an uncaught exception. the ensure block will get run.

More about Ruby Maciej Mensfeld Exceptions - else If the else clause is present, it goes after the rescue clauses and before any ensure. The body of an else clause is executed only if no exceptions are raised by the main body of code.

More about Ruby Maciej Mensfeld Class Exception To be even more specific about an error, you can define your own Exception subclass

More about Ruby Maciej Mensfeld Class Exception

More about Ruby Maciej Mensfeld Modules Modules are a way of grouping together methods, classes, and constants. Modules give you two major benefits: 1.Modules provide a namespace and prevent name clashes 2.Modules implement the mixin facility Modules define a namespace, a sandbox in which your methods and constants can play without having to worry about being stepped on by other methods and constants.

More about Ruby Maciej Mensfeld Modules

More about Ruby Maciej Mensfeld Modules

More about Ruby Maciej Mensfeld Modules

More about Ruby Maciej Mensfeld Modules – Class methods

More about Ruby Maciej Mensfeld Instance extending

More about Ruby Maciej Mensfeld Ruby Gems A gem is a packaged Ruby application or library. It has a name (e.g. rake) and a version (e.g ). RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries (in a self-contained format called a "gem"), a tool designed to easily manage the installation of gems, and a server for distributing them. It is analogous to EasyInstall for the Python programming language. RubyGems is now part of the standard library from Ruby version 1.9.

More about Ruby Maciej Mensfeld Ruby Gems Listing all installed gems Installing remote gem

More about Ruby Maciej Mensfeld Ruby Gems Using Ruby Gems

More about Ruby Maciej Mensfeld Blocks, Procs and Lambdas Taken from: Blocks, Procs and lambdas (referred to as closures in Computer Science) are one of the most powerful aspects of Ruby, and also one of the most misunderstood. This is probably because Ruby handles closures in a rather unique way. Making things more complicated is that Ruby has four different ways of using closures

More about Ruby Maciej Mensfeld Blocks, Procs and Lambdas - Yielding So to recap what is happening: 1. Send iterate! to the Array of numbers. 2. When yield is called with the number n (first time is 1, second time is 2, etc…), pass the number to the block of code given. 3. The block has the number available (also called n) and squares it. As it is the last value handled by the block, it is returned automatically. 4. Yield outputs the value returned by the block, and rewrites the value in the array. 5. This continues for each element in the array. What we now have is a flexible way to interact with our method. Think of blocks as giving your method an API, where you can determine to square each value of the array, cube them or convert each number to a string and print them to the screen. The options are infinite, making your method very flexible, and as such, very powerful.

More about Ruby Maciej Mensfeld Blocks, Procs and Lambdas - Proc Blocks are very handy and syntactically simple, however we may want to have many different blocks at our disposal and use them multiple times. As such, passing the same block again and again would require us to repeat ourself. However, as Ruby is fully object- oriented, this can be handled quite cleanly by saving reusable code as an object itself. This reusable code is called a Proc (short for procedure). The only difference between blocks and Procs is that a block is a Proc that cannot be saved, and as such, is a one time use solution.

More about Ruby Maciej Mensfeld Blocks, Procs and Lambdas - Proc The above is how most languages handle closures and is exactly the same as sending a block. However, this does not look „Ruby like”. The above reason is exactly why Ruby has blocks to begin with, and that is to stay within its familiar end concluding syntax.

More about Ruby Maciej Mensfeld Blocks, Procs and Lambdas - Proc What if we want to pass two or more closures to a method? If this is the case, blocks quickly become too limiting. By having Procs however, we can do something like this:

More about Ruby Maciej Mensfeld Blocks, Procs and Lambdas - Lambdas On first look, lambdas seem to be exactly the same as Procs. However, there are two subtle differences. The first difference is that, unlike Procs, lambdas check the number of arguments passed.

More about Ruby Maciej Mensfeld Blocks, Procs and Lambdas - Lambdas The second difference is that lambdas have diminutive returns. What this means is that while a Proc return will stop a method and return the value provided, lambdas will return their value to the method and let the method continue on. Part of Ruby’s syntax is that arguments (a Proc in this example) cannot have a return keyword in it. However, a lambda acts just like a method, which can have a literal return, and thus sneaks by this requirement unscathed!

More about Ruby Maciej Mensfeld Blocks, Procs and Lambdas

MongoDB Maciej Mensfeld MongoDB introduction MongoDB is a document database that provides high performance, high availability, and easy scalability.

MongoDB Maciej Mensfeld MongoDB introduction - Document Database Documents (objects) map nicely to programming language data types. Embedded documents and arrays reduce need for joins. Dynamic schema makes polymorphism easier. - High Performance Embedding makes reads and writes fast. Indexes can include keys from embedded documents and arrays. Optional streaming writes (no acknowledgments). - High Availability Replicated servers with automatic master failover. - Easy Scalability Automatic sharding distributes collection data across machines. Eventually-consistent reads can be distributed over replicated servers.

MongoDB Maciej Mensfeld MongoDB introduction

MongoDB Maciej Mensfeld MongoDB introduction

MongoDB Maciej Mensfeld MongoDB introduction

MongoDB Maciej Mensfeld MongoDB introduction

MongoDB Maciej Mensfeld MongoDB introduction

OOP Maciej Mensfeld THX Maciej Mensfeld dev.mensfeld.pl github.com/mensfeld