CHAPTER 8: USING OBJECTS

Relaterede dokumenter
Basic statistics for experimental medical researchers

Project Step 7. Behavioral modeling of a dual ported register set. 1/8/ L11 Project Step 5 Copyright Joanne DeGroat, ECE, OSU 1

Privat-, statslig- eller regional institution m.v. Andet Added Bekaempelsesudfoerende: string No Label: Bekæmpelsesudførende

PARALLELIZATION OF ATTILA SIMULATOR WITH OPENMP MIGUEL ÁNGEL MARTÍNEZ DEL AMOR MINIPROJECT OF TDT24 NTNU

Linear Programming ١ C H A P T E R 2

Portal Registration. Check Junk Mail for activation . 1 Click the hyperlink to take you back to the portal to confirm your registration

Black Jack --- Review. Spring 2012

Vina Nguyen HSSP July 13, 2008

ECE 551: Digital System * Design & Synthesis Lecture Set 5

Aktivering af Survey funktionalitet

Software 1 with Java. Recitation No. 7 (Servlets, Inheritance)

Central Statistical Agency.

The X Factor. Målgruppe. Læringsmål. Introduktion til læreren klasse & ungdomsuddannelser Engelskundervisningen

IBM Network Station Manager. esuite 1.5 / NSM Integration. IBM Network Computer Division. tdc - 02/08/99 lotusnsm.prz Page 1

Skriftlig Eksamen Kombinatorik, Sandsynlighed og Randomiserede Algoritmer (DM528)

Det er muligt at chekce følgende opg. i CodeJudge: og

DET KONGELIGE BIBLIOTEK NATIONALBIBLIOTEK OG KØBENHAVNS UNIVERSITETS- BIBLIOTEK. Index

Vores mange brugere på musskema.dk er rigtig gode til at komme med kvalificerede ønsker og behov.

Den nye Eurocode EC Geotenikerdagen Morten S. Rasmussen

User Manual for LTC IGNOU

GUIDE TIL BREVSKRIVNING

Hvor er mine runde hjørner?

Engelsk. Niveau C. De Merkantile Erhvervsuddannelser September Casebaseret eksamen. og

Engelsk. Niveau D. De Merkantile Erhvervsuddannelser September Casebaseret eksamen. og

Unitel EDI MT940 June Based on: SWIFT Standards - Category 9 MT940 Customer Statement Message (January 2004)

United Nations Secretariat Procurement Division

FAST FORRETNINGSSTED FAST FORRETNINGSSTED I DANSK PRAKSIS

How Long Is an Hour? Family Note HOME LINK 8 2

Terese B. Thomsen 1.semester Formidling, projektarbejde og webdesign ITU DMD d. 02/

Skriftlig Eksamen Diskret matematik med anvendelser (DM72)

PMDK PC-Side Basic Function Reference (Version 1.0)

Barnets navn: Børnehave: Kommune: Barnets modersmål (kan være mere end et)

Titel: Barry s Bespoke Bakery

ATEX direktivet. Vedligeholdelse af ATEX certifikater mv. Steen Christensen

South Baileygate Retail Park Pontefract

Heuristics for Improving

DK - Quick Text Translation. HEYYER Net Promoter System Magento extension

E-PAD Bluetooth hængelås E-PAD Bluetooth padlock E-PAD Bluetooth Vorhängeschloss

Shooting tethered med Canon EOS-D i Capture One Pro. Shooting tethered i Capture One Pro 6.4 & 7.0 på MAC OS-X & 10.8

Brug sømbrættet til at lave sjove figurer. Lav fx: Få de andre til at gætte, hvad du har lavet. Use the nail board to make funny shapes.

Bilag. Resume. Side 1 af 12

Trolling Master Bornholm 2015

UNISONIC TECHNOLOGIES CO.,

Sport for the elderly

From innovation to market

Learnings from the implementation of Epic

Udbud på engelsk i UCL. Skabelon til beskrivelse

INGEN HASTVÆRK! NO RUSH!

Our activities. Dry sales market. The assortment

Userguide. NN Markedsdata. for. Microsoft Dynamics CRM v. 1.0

3D NASAL VISTA TEMPORAL

Remember the Ship, Additional Work

X M Y. What is mediation? Mediation analysis an introduction. Definition

Skriftlig Eksamen Beregnelighed (DM517)

Design by Contract Bertrand Meyer Design and Programming by Contract. Oversigt. Prædikater

OXFORD. Botley Road. Key Details: Oxford has an extensive primary catchment of 494,000 people

Trolling Master Bornholm 2016 Nyhedsbrev nr. 6

Strings and Sets: set complement, union, intersection, etc. set concatenation AB, power of set A n, A, A +

IPv6 Application Trial Services. 2003/08/07 Tomohide Nagashima Japan Telecom Co., Ltd.

Danish Language Course for International University Students Copenhagen, 12 July 1 August Application form

Den uddannede har viden om: Den uddannede kan:

Appendix 1: Interview guide Maria og Kristian Lundgaard-Karlshøj, Ausumgaard

Richter 2013 Presentation Mentor: Professor Evans Philosophy Department Taylor Henderson May 31, 2013

Læs venligst Beboer information om projekt vandskade - sikring i 2015/2016

To the reader: Information regarding this document

The purpose of our Homepage is to allow external access to pictures and videos taken/made by the Gunnarsson family.

extreme Programming Kunders og udvikleres menneskerettigheder

Help / Hjælp

Tema: Pets Fag: Engelsk Målgruppe: 4. klasse Titel: Me and my pet Vejledning Lærer

Trolling Master Bornholm 2015

Molio specifications, development and challenges. ICIS DA 2019 Portland, Kim Streuli, Molio,

Status på det trådløse netværk

SOFTWARE PROCESSES. Dorte, Ida, Janne, Nikolaj, Alexander og Erla

Blomsten er rød (af Harry Chapin, oversat af Niels Hausgaard)

3D NASAL VISTA 2.0

PR day 7. Image+identity+profile=branding

Bookingmuligheder for professionelle brugere i Dansehallerne

Fejlbeskeder i SMDB. Business Rules Fejlbesked Kommentar. Validate Business Rules. Request- ValidateRequestRegist ration (Rules :1)

Eksempel på eksamensspørgsmål til caseeksamen

University of Copenhagen Faculty of Science Written Exam - 3. April Algebra 3

MSE PRESENTATION 2. Presented by Srunokshi.Kaniyur.Prema. Neelakantan Major Professor Dr. Torben Amtoft

Trolling Master Bornholm 2016 Nyhedsbrev nr. 8

Design by Contract. Design and Programming by Contract. Oversigt. Prædikater

Improving data services by creating a question database. Nanna Floor Clausen Danish Data Archives

DSB s egen rejse med ny DSB App. Rubathas Thirumathyam Principal Architect Mobile

Danish Language Course for Foreign University Students Copenhagen, 13 July 2 August 2016 Advanced, medium and beginner s level.

what is this all about? Introduction three-phase diode bridge rectifier input voltages input voltages, waveforms normalization of voltages voltages?

The River Underground, Additional Work

CS 4390/5387 SOFTWARE V&V LECTURE 5 BLACK-BOX TESTING - 2

On the complexity of drawing trees nicely: corrigendum

Engineering of Chemical Register Machines

Financial Literacy among 5-7 years old children

2a. Conceptual Modeling Methods

Aarhus Universitet, Science and Technology, Computer Science. Exam. Wednesday 27 June 2018, 9:00-11:00

Varenr.: højre venstre º højre med coating º venstre med coating

DANSK INSTALLATIONSVEJLEDNING VLMT500 ADVARSEL!

Design til digitale kommunikationsplatforme-f2013

Strategic Capital ApS has requested Danionics A/S to make the following announcement prior to the annual general meeting on 23 April 2013:

Trolling Master Bornholm 2014

Dårlig litteratur sælger - Trykkekultur i 1800-tallets Storbritannien og idag. Maria Damkjær Post.doc. i Engelsk Litteratur

Transkript:

Ruby: Philosophy & Implementation CHAPTER 8: USING OBJECTS Introduction to Computer Science Using Ruby Ruby is the latest in the family of Object Oriented Programming Languages As such, its designer studied the problems and promises of past languages Ruby is an extreme implementation of such a language, containing large complexity on one hand and the ability to ignore any such complexity on the other hand Ruby: Philosophy & Implementation Classes Eliminate ANY unnecessary statements, declarations and complexity Startup has to be very simple Complexity increase has to be unlimited Development is supported by interactive capability Portability is assured via an interpretive implementation Programs can be millions of lines of code Eventually, they become very difficult to debug and maintain Classes are created to organize programs and data based on functionality 1

Objects Classes & Objects Classes define the characteristics and behaviors of objects belonging to them Classes provide an abstraction of possible objects Objects are the instantiation of classes They have a name and possess all the properties of the class Example: Simple variables and their methods Classes are designed to separate key activities in a program Objects instantiated from classes provide the implementation of the program Activities are isolated Communicate information without knowing how it is produced Classes enable programs to be compartmentalized Programmers can work at the same time on different classes without running into each other Methods Built-in Classes & their Objects Classes have their own private chunks of data and actions Actions that an object instantiated from a class may perform are referred to as Methods that belong to that Class Everything in Ruby is an Object, even a simple variable As such, it has to be instantiated from a Class In Ruby, instantiation is many times done automatically, using hidden Class definitions This is one of the ways to eliminate declarations and various auxiliary and obscure statements 2

Built-in Classes Built-in Objects Classes A Class defines the characteristics and behaviors of an object Contains the variables and the code necessary to implement the operations (Methods) of the object Examples of Built-in Classes: Array Fixnum Float String There are many more classes than these It is not required that you know HOW they do what they do, but it is required that you know WHAT they do, how to find them, and how to deploy them Built-in Classes & their Objects In Ruby, instantiation can be done automatically using hidden Class definitions, or can be done explicitly, using the proper method Example: # Automatic creation no Class name... arr = [1,2,3, Wow ] This is an automatic creation of an Object (in this case: arr) No class name is used Class is hidden no method Built-in Classes & their Objects In Ruby, instantiation is done automatically many times, using hidden Class definitions, or can be done explicitly. Example: # instantiate an object from the class Array arr = Array.new This is an explicit creation of an Object In this case arr: instantiating it from the class Array using the built-in method new 3

Built-in Classes & their Methods Figure 8.1: String API Documentation You can understand Class functionality by looking at the Ruby API, or Application Program(ming) Interface API allows the use of built-in functionality (that is, the built-in classes and their methods) without knowing the specifics of the implementation The next slides show the API documentation for the String class It is taken straight out of the book which is taken straight from the Ruby public information (with proper attribution) Figure 8.1: String API Documentation Built-in Methods http://ruby-doc.org/core-1.9.3/string.html The length method descriptor is str.length => integer Means that the method will return an integer irb(main):001:0> "hello".length => 5

Built-in Methods Parameter Passing Not all methods are this simple: Parameters are data supplied to a method (or to a Class see later) See the API for the description of the built-in methods that require parameter(s) (variable(s) in parenthesis Methods with parameters send the value of the variable to the implementing code Example 8.1: Parameter Passing Parameter Passing Look at the made up multiplier method: 1 x = 3 2 y = x.multiplier() 3 puts "The number is: " + y.to_s It multiplies the value of the parameter by x Output: The number is 12. The method works like a black box The program inside is not known and doesn t matter Only the function, thus the output, is important Figure 8.: Black Box for Multiplier Method 5

Example 8.2: Parameter Passing Example 8.3: Split Example #2 Example of Split (an actual Ruby built-in method): This method splits strings into array elements based on the parameter passed 1 my_string = "Good;day;sir!" 2 arr = my_string.split(";") 3 puts arr 5 # The following array is created: 6 # arr[0]: "Good" 7 # arr[1]: "day" 8 # arr[2]: "sir! Change the parameter to a : 1 my_string = "Good;day;sir!" 2 arr = my_string.split("a") 3 puts arr 5 # The following array is created: 6 # arr[0]: "Good;d" 7 # arr[1]: "y;sir! Output: Good;d y;sir! Example 8.: Split Example #3 Summary A parameter not found in the string will result in an array containing a string that isn t split 1 my_string = "Good;day;sir!" 2 arr = my_string.split("z") 3 puts arr 5 # The following array is created: 6 # arr[0]: "Good;day;sir! Output: Good;day;sir! Classes define the characteristics and behaviors of objects belonging to the class Objects are instantiations of a class: they have a name and possess all the properties of the class, namely the variables and the methods The application user interface, or API, is an interface used to communicate with some underlying functionality Parameter passing is used to transfer information to an object 6