Learning Ruby by Michael Fitzgerald Publisher: O'reilly Pub Date: May 01, 2007 Print ISBN-10: 0-596-52986-4 Print ISBN-13: 978-0-59-652986-4 Pages: 255

Total Page:16

File Type:pdf, Size:1020Kb

Learning Ruby by Michael Fitzgerald Publisher: O'reilly Pub Date: May 01, 2007 Print ISBN-10: 0-596-52986-4 Print ISBN-13: 978-0-59-652986-4 Pages: 255 Learning Ruby by Michael Fitzgerald Publisher: O'Reilly Pub Date: May 01, 2007 Print ISBN-10: 0-596-52986-4 Print ISBN-13: 978-0-59-652986-4 Pages: 255 Copyright Dedication Preface Chapter 1. Ruby Basics Section 1.1. Hello, Matz Section 1.2. Interactive Ruby Section 1.3. Resources Section 1.4. Installing Ruby Section 1.5. Permission Denied Section 1.6. Associating File Types on Windows Section 1.7. Review Questions Chapter 2. A Quick Tour of Ruby Section 2.1. Ruby Is Object-Oriented Section 2.2. Ruby's Reserved Words Section 2.3. Comments Section 2.4. Variables Section 2.5. Strings Section 2.6. Numbers and Operators Section 2.7. Conditional Statements Section 2.8. Arrays and Hashes Section 2.9. Methods Section 2.10. Blocks Section 2.11. Symbols Section 2.12. Exception Handling Section 2.13. Ruby Documentation Section 2.14. Review Questions Chapter 3. Conditional Love Section 3.1. The if Statement Section 3.2. The case Statement Section 3.3. The while Loop Section 3.4. The loop Method Section 3.5. The for loop Section 3.6. Execution Before or After a Program Section 3.7. Review Questions Chapter 4. Strings Section 4.1. Creating Strings Section 4.2. Concatenating Strings Section 4.3. Accessing Strings Section 4.4. Comparing Strings Section 4.5. Manipulating Strings Section 4.6. Case Conversion Section 4.7. Managing Whitespace, etc. Section 4.8. Incrementing Strings Section 4.9. Converting Strings Section 4.10. Regular Expressions Section 4.11. 1.9 and Beyond Section 4.12. Review Questions Chapter 5. Math Section 5.1. Class Hierarchy and Included Modules Section 5.2. Converting Numbers Section 5.3. Basic Math Operations Section 5.4. Ranges Section 5.5. Inquiring About Numbers Section 5.6. More Math Methods Section 5.7. Math Functions Section 5.8. Rational Numbers Section 5.9. Prime Numbers Section 5.10. Review Questions Chapter 6. Arrays Section 6.1. Creating Arrays Section 6.2. Accessing Elements Section 6.3. Concatenation Section 6.4. Set Operations Section 6.5. Unique Elements Section 6.6. Blow Your Stack Section 6.7. Comparing Arrays Section 6.8. Changing Elements Section 6.9. Deleting Elements Section 6.10. Arrays and Blocks Section 6.11. Sorting Things and About Face Section 6.12. Multidimensional Arrays Section 6.13. 1.9 and Beyond Section 6.14. Other Array Methods Section 6.15. Review Questions Chapter 7. Hashes Section 7.1. Creating Hashes Section 7.2. Accessing Hashes Section 7.3. Iterating over Hashes Section 7.4. Changing Hashes Section 7.5. Converting Hashes to Other Classes Section 7.6. 1.9 and Beyond Section 7.7. Other Hash Methods Section 7.8. Review Questions Chapter 8. Working with Files Section 8.1. Directories Section 8.2. Creating a New File Section 8.3. Opening an Existing File Section 8.4. Deleting and Renaming Files Section 8.5. File Inquiries Section 8.6. Changing File Modes and Owner Section 8.7. The IO Class Section 8.8. Review Questions Chapter 9. Classes Section 9.1. Defining the Class Section 9.2. Instance Variables Section 9.3. Accessors Section 9.4. Class Variables Section 9.5. Class Methods Section 9.6. Inheritance Section 9.7. Modules Section 9.8. public, private, or protected Section 9.9. Review Questions Chapter 10. More Fun with Ruby Section 10.1. Formatting Output with sprintf Section 10.2. Processing XML Section 10.3. Date and Time Section 10.4. Reflection Section 10.5. Using Tk Section 10.6. Metaprogramming Section 10.7. RubyGems Section 10.8. Exception Handling Section 10.9. Creating Documentation with RDoc Section 10.10. Embedded Ruby Section 10.11. Review Questions Chapter 11. A Short Guide to Ruby on Rails Section 11.1. Where Did Rails Come From Section 11.2. Why Rails? Section 11.3. What Have Other Folks Done with Rails? Section 11.4. Hosting Rails Section 11.5. Installing Rails Section 11.6. Learning Rails Section 11.7. A Brief Tutorial Section 11.8. Review Questions Appendix A. Ruby Reference Section A.1. Ruby Interpreter Section A.2. Ruby's Reserved Words Section A.3. Operators Section A.4. Escape Characters Section A.5. Predefined Variables Section A.6. Global Constants Section A.7. Regular Expressions Section A.8. String Unpack Directives Section A.9. Array Pack Directives Section A.10. Sprintf Flags and Field Types Section A.11. File Tests Section A.12. Time Formatting Directives Section A.13. RDoc Options Section A.14. Rake Appendix B. Answers to Review Questions Section B.1. Review Questions Section B.2. Review Questions Section B.3. Review Questions Section B.4. Review Questions Section B.5. Review Questions Section B.6. Review Questions Section B.7. Review Questions Section B.8. Review Questions Section B.9. Review Questions Section B.10. Review Questions Section B.11. Review Questions Glossary About the Author Colophon Index Copyright Learning Ruby by Michael Fitzgerald Copyright © 2007 Michael Fitzgerald. All rights reserved. Printed in the United States of America. Published by O'Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O'Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safari.oreilly.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or [email protected]. Editor: Simon St.Laurent Production Editor: Lydia Onofrei Proofreader: Lydia Onofrei Indexer: John Bickelhaupt Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrators: Robert Romano and Jessamyn Read Printing History: May 2007: First Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly Media, Inc. Learning Ruby, the image of a giraffe, and related trade dress are trademarks of O'Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O'Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. ISBN-10: 0-596-52986-4 ISBN-13: 978-0-596-52986-4 [M] Dedication Robert Wayne Darrah 1950-2006 Till we meet again Preface Ruby has gotten a lot of attention since the appearance of Ruby on Rails, the web application framework written in Ruby. The attention is way past due. Ruby has been around as long as Java but enjoyed only limited attention outside of Japan until around 2000. In the last few years, Ruby's popularity has steadily grown, and with good reason. Who Should Read This Book? Generally, I figure two kinds of readers will buy this book: experienced programmers who want to learn Ruby, and new programmers who want to learn to program. I have the interesting job of catering to both while trying not to tick off either. It's a balancing act, and this is how I'll handle it: I am going to address you as if you are already a competent programmer, but I'll also provide plenty of help for beginners, mostly in the form of notes or sidebars. I'll let you know when you can skip a section if you are already a heavy hitter. If you're a fairly experienced programmer, you might just want to read the code examples first, from the beginning of the book to the end, skimming the explanations surrounding the examples as needed. You should be able to see what's going on fairly quickly just by keeping your eyes on the code. The code is laid out in a more or less logical fashion (to me at least), so you should be able to figure out Ruby in fairly short order. If you are new to programming, I have attempted to make your job a little easier by explaining things as I go along. How This Book Works Do you have to know everything about a car before you start driving? Did you have to know anything about fuel injection, combustion, or timing belts to drive? Of course not. It's the same with programming in a new language. I am going to show you lots of Ruby programs, many of them just one-liners, and then tell you how and why they work-just enough to get you rolling down the road. I take this approach because I believe we do most of our learning by observing, imitating, and playing. I plan to do a lot of that in this book. You should know up front that this is a just-get-in-and-drive book. In other words, you can drive a car even if you don't know whether its got six or eight cylinders. David Heinemeier Hansson, inventor of Ruby on Rails, said something I like: "People learn by changing a little thing, reloading, and seeing the change." He's right on. That's my experience: over the years I have learned more by hacking code than by reading about it. I also move as quickly as possible, not getting bogged down in the quicksand of details. The details will come in time, as they are needed; the main thing I want to give you now is forward movement and momentum. If you just follow along with what I'm doing, running the programs and altering them to your taste, you'll learn quickly.
Recommended publications
  • Ruby Useful Resources
    RRUUBBYY -- UUSSEEFFUULL RREESSOOUURRCCEESS http://www.tutorialspoint.com/ruby/ruby_resources.htm Copyright © tutorialspoint.com The following resources contain additional information on Ruby. Please use them to get more in- depth knowledge on this topic. Useful Links on Ruby Main Ruby Site − Official Ruby site. Find a complete list of all documentation, tutorials, news, etc. Ruby Documentation − Ruby documentation site. Ruby Application Archive − A collection of Ruby programs, libraries, documentations, and binary packages compiled for specific platforms. Ruby Installation − One-Click Ruby Installer for Windows. RubyForge − Open source project repository. Ruby on Rails − Official site for Ruby on Rails. RubyGems − Download link for RubyGem and other documentation. Rails APIs − A comprehensive list of Rails APIs Rails Conf − RailsConf, co-presented by Ruby Central, Inc. and O'Reilly Media, Inc., is the largest official conference dedicated to everything Rails. Ruby Central − Ruby Central, Inc., is a 501c3 tax-exempt organization, dedicated to Ruby support and advocacy. XSLT4R − Download a module for XSLT in Ruby. REXML − A powerful parser written in Ruby. Complete API documentation and installation is available at the site. Ruby LDAP − LDAP protocol implementation in Ruby. Complete API documentation is available. MySQL Homepage − Here you can download the latest MySQL release, get the MySQL news update. The mailing list is also a great resources for anyone who want to build dynamic websites using MySQL. Unix-based Web hosting − If you have a plan to host your website on a Unix-based Server, then you can check this site. Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js.
    [Show full text]
  • Def Rubyconf Table of Contents
    Program Guide def rubyconf Table of Contents General Info 04 Meet the Team 06 Keynote Speakers 08 Daily Schedule 10 Conference Map 19 02 03 General Information WiFi Access Network: Millennium_Event Password: ruby Registration Speaker Lounge Tuesday 7:30AM-6:00PM Tuesday 9:00AM-5:00PM Wednesday 8:30AM-7:00PM Wednesday 10:00AM-5:00PM Thursday 8:30AM-5:30PM Thursday 10:00AM-3:00PM T-Shirt Pickup Lost and Found Located at Registration. Located at Registration. Tuesday 12:10PM-1:20PM Contact Us 12:00PM-5:30PM Wednesday [email protected] @rubyconf Thursday 12:00PM-5:30PM 04 05 Meet the Team Marty Haught Heather Johnson Program Chair Event Producer Software architect/entrepreneur that runs Haught Codeworks Heather is the Event Producer at Ruby Central. After years of building both great software and teams. Marty is heavily involved planning and producing trade shows, she decided to shift her in the software community, most notably as an organizer of focus to planning conferences and events. She loves a good DIY RailsConf and RubyConf. Beyond his love for the outdoors, food project and spending time with her husband, daughter, and fur and music, Marty is busy raising his two children with his lovely children. wife and enjoying life. Eric Euresti Evan Phoenix Sponsorship Consultant Program Director Eric is part of the dynamic sales duo at Ruby Central. Before Evan is a Director at Ruby Central and long-time Ruby user. joining the team, he was a long-time volunteer at both RubyConf Additionally, he works for HashiCorp on infrastructure and helps and RailsConf, and is passionate about events and community.
    [Show full text]
  • Product End User License Agreement
    END USER LICENSE AGREEMENT If you have another valid, signed agreement with Licensor or a Licensor authorized reseller which applies to the specific Licensor Software, Software Services, Maintenance or Consulting Services you are downloading, accessing or otherwise receiving, that other agreement shall control; otherwise by using, downloading, installing, copying, or accessing Licensor Software, Software Services, Maintenance or Consulting Services, or by clicking on "I accept" on or adjacent to the screen where these Master Terms may be displayed, you hereby agree to be bound by and accept these Master Terms. These Master Terms shall also apply to any Maintenance or Consulting Services you later acquire from Licensor relating to the Software or Software Services. You may place orders under these Master Terms by submitting separate Order Form(s). Capitalized terms used in these Master Terms and not otherwise defined, are defined at https://terms.tibco.com/posts/845635-definitions. 1. License Models, License Grant, Rights and Restrictions. Licensor provides Software on a Perpetual, or Term basis, embedded and delivered as part of Equipment, as Software Services and on a Subscription basis. The Supplemental Terms, include, but are not limited to, the license grant, rights and restrictions for each of the foregoing (including for evaluation purposes) which are located at https://terms.tibco.com. The availability of Software in one or more of the foregoing license models is at Licensor's sole discretion. Additional license requirements and notices, if any, if not included at https://terms.tibco.com, shall be contained in the Documentation that is delivered with the applicable Software.
    [Show full text]
  • Rails 4 En Windows Y Linux Ubuntu – V 1.0.5 Beta – Pag 1/200 - Actualizado Al 7/10/ 2016 Sergio A
    Sergio A. Alonso - Rails 4 en Windows y Linux Ubuntu – v 1.0.5 Beta – pag 1"#00 - a$tuali%ado al &"10" 201' Sergio A. Alonso - Rails 4 en Windows y Linux Ubuntu – v 1.0.5 Beta – pag #"#00 - a$tuali%ado al &"10" 201' ¡Ud podría estar leyendo una copia vieja! ()equee la versión en el en$abe%ado de las )o,as- $ontra la última en el sitio o.$ial- )tt!/""r0uw.)ero1u.$o2 3esde allí en$ontrará el vín$ulo )acia la versión 2as actual- y un listado 2uy útil de erratas- $orrec$iones- e in$luso una sec$ión donde !ostear errores y sugeren$ias. Este libro es tan gratis como una cerveza (free-as-a-beer) (uente sie2!re con la 6ltima versión dis!onible en P38. Mi ob,etivo es que lo lea la mayor cantidad posible de personas, y que éstas me retornen sus im!resiones, errores encontrados y sugerencias en general. De he$ho, ne$esito de estos re!ortes para obtener un nivel a!re$iable de $alidad, tal *ue el libro sea digno de ser llevado a una im!renta. Una ve% que el libro este listo, pretendo seguir de,5ndolo libre, publicarlo en la editorial Bubok ;i2!resión a de2anda<- y *uedar2e como mu$ho con u=s 5 de regalías por libro... al menos para ha$erle creer a mi es!osa que hago dinero con esto. Creo que si el libro lo mere$e, la gente se cansar5 de leerlo en !antalla- y querr5 tener un e,e2!lar en pa!el.
    [Show full text]
  • Roles in a Networked Software Development Ecosystem: a Case Study in Github Patrick Wagstrom IBM TJ Watson Research Center Hawthorne, NY, [email protected]
    University of Nebraska - Lincoln DigitalCommons@University of Nebraska - Lincoln CSE Technical reports Computer Science and Engineering, Department of 2012 Roles in a Networked Software Development Ecosystem: A Case Study in GitHub Patrick Wagstrom IBM TJ Watson Research Center Hawthorne, NY, [email protected] Corey Jergensen University of Nebraska-Lincoln, [email protected] Anita Sarma University of Nebraska-Lincoln, [email protected] Follow this and additional works at: http://digitalcommons.unl.edu/csetechreports Wagstrom, Patrick; Jergensen, Corey; and Sarma, Anita, "Roles in a Networked Software Development Ecosystem: A Case Study in GitHub" (2012). CSE Technical reports. 149. http://digitalcommons.unl.edu/csetechreports/149 This Article is brought to you for free and open access by the Computer Science and Engineering, Department of at DigitalCommons@University of Nebraska - Lincoln. It has been accepted for inclusion in CSE Technical reports by an authorized administrator of DigitalCommons@University of Nebraska - Lincoln. Roles in a Networked Software Development Ecosystem: A Case Study in GitHub Patrick Wagstrom Corey Jergensen, Anita Sarma IBM TJ Watson Research Center Computer Science and Engineering Department 19 Skyline Dr University of Nebraska, Lincoln Hawthorne, NY, USA 10532 Lincoln, NE, USA 68588 [email protected] {cjergens,asarma}@cse.unl.edu ABSTRACT tiple languages and utilizing multiple different development Open source software development has evolved beyond single frameworks and libraries, For example, development of a web projects into complex networked ecosystems of projects that application may use the JavaScript library jQuery for the user share portions of their code, social norms, and developer commu- interaction, Ruby on Rails for the backend processing, and Rack nities.
    [Show full text]
  • Extending Facter and Puppet
    Pro Puppet James Turnbull Jeffrey McCune Pro Puppet Copyright © 2011 by James Turnbull and Jeffrey McCune All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN 978-1-4302-3057-1 ISBN 978-1-4302-3058-8 (eBook) Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. President and Publisher: Paul Manning Lead Editor: Frank Pohlmann Technical Reviewer: Jessica Fraser Editorial Board: Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Jeff Olson, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Coordinating Editor: Anita Castro Copy Editor: Seth Kline Compositor: Bytheway Publishing Services Indexer: John Collin Artist: April Milne Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring Street, 6th Floor, New York, NY 10013.
    [Show full text]
  • Rubywrite: a Ruby-Embedded Domain-Specific Language for High-Level Transformations
    RubyWrite: A Ruby-Embedded Domain-Specific Language for High-Level Transformations Andrew Keep, Arun Chauhan, Chun-Yu Shei, and Pushkar Ratnalikar Indiana University, Bloomington, IN 47405, USA fakeep,achauhan,cshei,[email protected] Abstract. We introduce a Domain Specific Language (DSL), called RubyWrite, embedded within Ruby, with the goal of providing an ex- tensible, effective, portable, and easy to use framework for encoding source-level transformations. Embedding within Ruby provides access to the powerful features of Ruby, including its purely object-oriented design and meta-programming capabilities. The syntactic flexibility and advanced language features of Ruby drove our choice of it as the host lan- guage. Easy integration of external C interfaces seamlessly within Ruby lets us move performance critical operations to C, or link with external libraries. RubyWrite was developed to aid our compiler research where it provides the core of three compiler infrastructure development projects, and is used as a teaching aid in a graduate-level compilers course. We expect RubyWrite to be widely applicable and a proof of concept in leveraging an existing modern language to write a portable compiler in- frastructure core. 1 Introduction We describe a Domain Specific Language (DSL), embedded within Ruby, aimed at simplifying the task of source-level transformations through term-rewriting. The DSL, called RubyWrite, is motivated by the need for a compiler development environment that allows easy integration of source-level transformations with program analysis. After spending frustrating months trying to develop a compiler for matlab in C++ a few years ago, we made the decision to move to a domain-specific lan- guage for compiler development.
    [Show full text]
  • Ruby on Rails
    Ruby.learn{ |stuff| } ● What is Ruby? ● What features make it interesting to me (and maybe you)? ● A quick, idiosyncratic tour of the Ruby ecosphere. Tuesday Software Lunch Talk: March 4, 2008 What is it? ● a dynamic, object-oriented, open source programming language... ● with a uniquely (but not too uniquely), expressive syntax ● dynamically or “duck” typed ● influenced by Perl, Smalltalk, Eiffel, Ada and Lisp ● has aspects of functional and imperative programming styles History ● created by Yukihiro “Matz” Matsumoto on Feb 24 1993, released to public in 1995 ● “Ruby” coined in comparison to “Perl” Philosophy (the “Ruby Way”) ● emphasize programmer needs over computer needs ● encourage good design, good APIs ● Principle of Least Surprise (POLS) – the language should behave in such a way as to minimize confusion for experienced users ● “Everything should be a simple as possible, but no simpler.” - Einstein ● orthogonality ● change at runtime is not to be feared Interesting Stuff... ● Is Not a Ruby tutorial – http://tryruby.hobix.com/ – Programming Ruby: The Pragmatic Programmer's Guide – our just google it – you want something totally different? ● http://poignantguide.net/ruby/ ● Is what I find interesting/different/well done about Ruby. Everything's an Object ● no exceptions Falsiness ● only false and nil are falsey. Not 0. Symbols ● labels ● lightweight strings with no behaviour ● often used as hash keys Blocks ● another name for a Ruby block is a “closure” ● clo-sure [kloh-zher] – noun. A function that is evaluated in an environment containing one or more bound variables. Procs ● anonymous subroutines or closures with a life of their own Adding Methods to Classes ● You can add methods to an object at runtime in several ways..
    [Show full text]
  • Ruby Programming
    Ruby Programming Wikibooks.org December 1, 2012 On the 28th of April 2012 the contents of the English as well as German Wikibooks and Wikipedia projects were licensed under Creative Commons Attribution-ShareAlike 3.0 Unported license. An URI to this license is given in the list of figures on page 249. If this document is a derived work from the contents of one of these projects and the content was still licensed by the project under this license at the time of derivation this document has to be licensed under the same, a similar or a compatible license, as stated in section 4b of the license. The list of contributors is included in chapter Contributors on page 243. The licenses GPL, LGPL and GFDL are included in chapter Licenses on page 253, since this book and/or parts of it may or may not be licensed under one or more of these licenses, and thus require inclusion of these licenses. The licenses of the figures are given in the list of figures on page 249. This PDF was generated by the LATEX typesetting software. The LATEX source code is included as an attachment (source.7z.txt) in this PDF file. To extract the source from the PDF file, we recommend the use of http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/ utility or clicking the paper clip attachment symbol on the lower left of your PDF Viewer, selecting Save Attachment. After extracting it from the PDF file you have to rename it to source.7z. To uncompress the resulting archive we recommend the use of http://www.7-zip.org/.
    [Show full text]
  • The Ruby Intermediate Language ∗
    The Ruby Intermediate Language ∗ Michael Furr Jong-hoon (David) An Jeffrey S. Foster Michael Hicks University of Maryland, College Park ffurr,davidan,jfoster,[email protected] Abstract syntax that is almost ambiguous, and a semantics that includes Ruby is a popular, dynamic scripting language that aims to “feel a significant amount of special case, implicit behavior. While the natural to programmers” and give users the “freedom to choose” resulting language is arguably easy to use, its complex syntax and among many different ways of doing the same thing. While this ar- semantics make it hard to write tools that work with Ruby source guably makes programming in Ruby easier, it makes it hard to build code. analysis and transformation tools that operate on Ruby source code. In this paper, we describe the Ruby Intermediate Language In this paper, we present the Ruby Intermediate Language (RIL), (RIL), an intermediate language designed to make it easy to ex- a Ruby front-end and intermediate representation that addresses tend, analyze, and transform Ruby source code. As far as we are these challenges. RIL includes an extensible GLR parser for Ruby, aware, RIL is the only Ruby front-end designed with these goals in and an automatic translation into an easy-to-analyze intermediate mind. RIL provides four main advantages for working with Ruby form. This translation eliminates redundant language constructs, code. First, RIL’s parser is completely separated from the Ruby in- unravels the often subtle ordering among side effecting operations, terpreter, and is defined using a Generalized LR (GLR) grammar, and makes implicit interpreter operations explicit.
    [Show full text]
  • Intro to Ruby
    Intro to Ruby Aaron Bartell [email protected] Copyright 2014 Aaron Bartell Ruby… a dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write. Matz desired a language which he himself enjoyed using, by minimizing programmer work and possible confusion - enter Ruby. - Est 1995 by Yukihiro "Matz" Matsumoto - Mass acceptance 2006 - Very active and well organized community - October 2013, on IBM i with PowerRuby Features: - variable declarations are unnecessary - variables are dynamically and strongly typed - syntax is simple and consistent - everything is an object - classes, methods, inheritance, etc. - NO SEMI COLONS!!! ruby-lang.org – Home website ruby-doc.org - Formal documentation codecademy.com - Learn Ruby in the browser for free amzn.to/1apcrse - Metaprogramming Ruby: Program Like the Ruby Pros Where can I use Ruby? Web apps with Rails - rubyonrails.org iOS with RubyMotion - rubymotion.com Android with Ruboto - ruboto.org Desktop (Mac, Linux, Windows) with Shoes - shoesrb.com ShoesRB.com irb (Interactive Ruby) is an interactive programming environment for Ruby that allows you to quickly test various coding ideas. ● Included with Ruby distribution. ● Symbolic link in /QOpenSys/usr/bin exists for the irb binary ● Great for learning Ruby through quick tests vs. editing files, saving, and invoking. ● irb is the foundation for the rails console. ● nil in screenshot is the reality that every Ruby method (i.e. puts) returns a value. ruby-doc.org/stdlib-2.0/libdoc/irb/rdoc/IRB.html - Formal documentation tryruby.org – Ruby code in the browser without having to install anything.
    [Show full text]
  • Rbfeatures: Feature-Oriented Programming with Ruby
    View metadata, citation and similar papers at core.ac.uk brought to you by CORE provided by Elsevier - Publisher Connector Science of Computer Programming 77 (2012) 152–173 Contents lists available at SciVerse ScienceDirect Science of Computer Programming journal homepage: www.elsevier.com/locate/scico rbFeatures: Feature-oriented programming with Ruby Sebastian Günther ∗, Sagar Sunkle Faculty of Computer Science, University of Magdeburg, Germany article info a b s t r a c t Article history: Features are pieces of core functionality of a program that is relevant to particular Available online 1 February 2011 stakeholders. Features pose dependencies and constraints among each other. These dependencies and constraints describe the possible number of variants of the program: Keywords: A valid feature configuration generates a specific variant with unique behavior. Feature- Feature-oriented programming Oriented Programming is used to implement features as program units. This paper Domain-specific languages Dynamic programming languages introduces rbFeatures, a feature-oriented programming language implemented on top of the dynamic programming language Ruby. With rbFeatures, programmers use software product lines, variants, and features as first-class entities. This allows several runtime reflection and modification capabilities, including the extension of the product line with new features and the provision of multiple variants. The paper gives a broad overview to the implementation and application of rbFeatures. We explain how features as first- class entities are designed and implemented, and discuss how the semantics of features are carefully added to Ruby programs. We show two case studies: The expression product line, a common example in feature-oriented programming, and a web application.
    [Show full text]