Metaprogramming Ruby

Total Page:16

File Type:pdf, Size:1020Kb

Metaprogramming Ruby What Readers Are Saying About Metaprogramming Ruby Reading this book was like diving into a new world of thinking. I tried a mix of Java and JRuby metaprogramming on a recent project. Using Java alone would now feel like entering a sword fight carrying only a banana, when my opponent is wielding a one-meter-long Samurai blade. Sebastian Hennebrüder Java Consultant and Trainer, laliluna.de This Ruby book fills a gap between language reference manuals and programming cookbooks. Not only does it explain various meta- programming facilities, but it also shows a pragmatic way of making software smaller and better. There’s a caveat, though; when the new knowledge sinks in, programming in more mainstream languages will start feeling like a chore. Jurek Husakowski Software Designer, Philips Applied Technologies Before this book, I’d never found a clear organization and explanation of concepts like the Ruby object model, closures, DSLs definition, and eigenclasses all spiced with real-life examples taken from the gems we usually use every day. This book is definitely worth reading. Carlo Pecchia Software Engineer I’ve had a lot of trouble finding a good way to pick up these meta- programming techniques, and this book is bar none the best way to do it. Paolo Perrotta makes it painless to learn Ruby’s most complex secrets and use them in practical applications. Chris Bunch Software Engineer Metaprogramming Ruby Program Like the Ruby Pros Paolo Perrotta The Pragmatic Bookshelf Raleigh, North Carolina Dallas, Texas Many of the designations used by manufacturers and sellers to distinguish their prod- ucts are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC. Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein. Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://www.pragprog.com Copyright © 2010 Paolo Perrotta. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmit- ted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher. Printed in the United States of America. ISBN-10: 1-934356-47-6 ISBN-13: 978-1-934356-47-0 Printed on acid-free paper. P1.0 printing, January 2010 Version: 2010-1-29 To Carlo. Contents Foreword 10 Acknowledgments 11 Introduction 13 The “M” Word ............................ 14 About This Book .......................... 21 About You .............................. 24 I Metaprogramming Ruby 26 1 Monday: The Object Model 27 1.1 Monday with Bill ...................... 27 1.2 Open Classes ........................ 28 1.3 The Truth About Classes .................. 33 1.4 Quiz: Missing Lines ..................... 45 1.5 What Happens When You Call a Method? . 46 1.6 Quiz: Tangle of Modules .................. 56 1.7 Object Model Wrap-Up ................... 59 2 Tuesday: Methods 60 2.1 A Duplication Problem ................... 61 2.2 Dynamic Methods ...................... 63 2.3 method_missing() ...................... 71 2.4 Quiz: Bug Hunt ....................... 82 2.5 More method_missing() ................... 84 3 Wednesday: Blocks 91 3.1 How to Handle Hump Day ................. 92 3.2 Quiz: Ruby# ......................... 93 3.3 Closures ........................... 96 3.4 instance_eval() ........................ 105 CONTENTS 8 3.5 Callable Objects ....................... 108 3.6 Writing a Domain-Specific Language ........... 116 3.7 Quiz: A Better DSL ..................... 118 4 Thursday: Class Definitions 122 4.1 Class Definitions Demystified ............... 123 4.2 Quiz: Class Taboo ...................... 130 4.3 Singleton Methods ..................... 132 4.4 Eigenclasses ......................... 137 4.5 Quiz: Module Trouble ................... 150 4.6 Aliases ............................ 152 4.7 Quiz: Broken Math ..................... 157 5 Friday: Code That Writes Code 160 5.1 Leading the Way ....................... 160 5.2 Kernel#eval ......................... 163 5.3 Quiz: Checked Attributes (Step 1) ............ 173 5.4 Quiz: Checked Attributes (Step 2) ............ 176 5.5 Quiz: Checked Attributes (Step 3) ............ 178 5.6 Quiz: Checked Attributes (Step 4) ............ 179 5.7 Hook Methods ........................ 180 5.8 Quiz: Checked Attributes (Step 5) ............ 186 6 Epilogue 188 II Metaprogramming in Rails 189 7 The Design of ActiveRecord 190 7.1 Preparing for the Tour ................... 191 7.2 The Design of ActiveRecord ................ 193 7.3 Lessons Learned ...................... 202 8 Inside ActiveRecord 206 8.1 Dynamic Attributes ..................... 206 8.2 Dynamic Finders ...................... 214 8.3 Lessons Learned ...................... 219 9 Metaprogramming Safely 224 9.1 Testing Metaprogramming ................. 224 9.2 Defusing Monkeypatches ................. 232 9.3 Lessons Learned ...................... 237 Report erratum this copy is (P1.0 printing, January 2010) CONTENTS 9 III Appendixes 239 A Common Idioms 240 A.1 Mimic Methods ....................... 240 A.2 Nil Guards .......................... 243 A.3 Tricks with Method Arguments .............. 244 A.4 Self Yield ........................... 248 A.5 Symbol#to_proc() ...................... 249 B Domain-Specific Languages 252 B.1 The Case for Domain-Specific Languages ........ 252 B.2 Internal and External DSLs ................ 254 B.3 DSLs and Metaprogramming ............... 255 C Spell Book 256 C.1 The Spells .......................... 256 D Bibliography 268 Index 269 Report erratum this copy is (P1.0 printing, January 2010) Foreword Ruby inherits characteristics from various languages — Lisp, Small- talk, C, and Perl, to name a few. Metaprogramming comes from Lisp (and Smalltalk). It’s a bit like magic, which makes something astonish- ing possible. There are two kinds of magic: white magic, which does good things, and black magic, which can do nasty things. Likewise, there are two aspects to metaprogramming. If you discipline yourself, you can do good things, such as enhancing the language without tweaking its syntax by macros or enabling internal domain-specific languages. But you can fall into the dark side of metaprogramming. Metaprogramming can confuse easily. Ruby trusts you. Ruby treats you as a grown-up programmer. It gives you great power such as metaprogramming. But you need to remember that with great power comes great responsibility. Enjoy programming in Ruby. matz October 2009 Acknowledgments Before I begin, I need to thank a few people. I’m talking to you, gen- tlemen: Joe Armstrong, Satoshi Asakawa, Paul Barry, Emmanuel Ber- nard, Roberto Bettazzoni, Ola Bini, Piergiuliano Bossi, Simone Busoli, Andrea Cisternino, Davide D’Alto, Mauro Di Nuzzo, Marco Di Timo- teo, Mauricio Fernandez, Jay Fields, Michele Finelli, Neal Ford, Flo- rian Frank, Sanne Grinovero, Federico Gobbo, Florian Groß, Sebastian Hennebrüder, Doug Hudson, Jurek Husakowski, Lyle Johnson, Luca Marchetti, MenTaLguY, Carlo Pecchia, Andrea Provaglio, Mike Roberts, Martin Rodgers, Jeremy Sydik, Andrea Tomasini, Marco Trincardi, Ivan Vaghi, Giancarlo Valente, Davide Varvello, Jim Weirich, and the dozens of readers who reported problems and errata while this book was in beta. Whether you provided reviews, quotes, fixes, opinions, or moral support, there’s at least one line in this book that changed for the bet- ter because of you. Did I say one line? For some of you, make that “a few chapters.” In particular, Ola, Satoshi, and Jurek deserve a special place on this page and my enduring gratitude. Thanks to the staff at the Pragmatic Bookshelf: Janet Furlow, Seth Maislin, Steve Peter, Susannah Davidson Pfalzer, and Kim Wimpsett. Dave and Andy, thank you for believing in this project when times got rough. Jill, thank you for making my awkward prose look so effortless. Our crunch week in Venice was a lot of hard work, but it was definitely worth it. And speaking of Venice: thank you, Lucio, for being such a dear old friend. Mom and Dad, thank you for your support, for your love, and for never asking why I was taking so long to finish this book. Most authors’ closing thanks go to their partners, and now I know why. When you’re about to finish a book, you turn back to the day when you started writing, and it feels so far away. I remember writing over lunch breaks, nights, and weekends, locked for days or weeks inside ACKNOWLEDGMENTS 12 my study, a hotel room in some foreign city, or a seashore house that would have suited a hermit. It’s such a lonesome endeavor—and yet,I never felt alone. Thank you, Mirella. Report erratum this copy is (P1.0 printing, January 2010) Will write code that writes code that writes code for food. Martin Rodgers Introduction Metaprogramming...it sounds cool! It sounds like a design technique for high-level enterprise architects or a fashionable buzzword that has found its way into press releases. In fact, far from being an abstract concept or
Recommended publications
  • O'reilly- Collaborating in Devops Culture
    Compliments of Collaborating in DevOps Culture Better Software Through Better Relationships Jennifer Davis & Ryn Daniels REPORT Teamwork powers DevOps GitHub powers teams GitHub helps more than two million organizations build better software together by centralizing discussions, automating tasks, and integrating with thousands of apps. Embraced by 31 million developers and counting, GitHub is where high-performing DevOps starts. Get started with a free trial at enterprise.github.com/contact Our on-premises and cloud solutions help enterprise teams: Collaborate Innovate Integrate Work across internal and Bring the power of Build on GitHub and external teams securely. the world’s largest open integrate with everything GitHub Enterprise includes source community to from legacy tools to access to on-premises developers at work, while cutting-edge apps, unifying Enterprise Server as well keeping your most critical your DevOps toolchain as Enterprise Cloud—now code behind the firewall so you can keep things with SOC 1, SOC 2, and ISAE with GitHub Connect. simple as you grow. 3000/3402 compliance. Work fast. Work secure. Work together. Start a free trial To find out more about GitHub Enterprise visit github.com/enterprise or email us at [email protected] Collaborating in DevOps Culture Better Software Through Better Relationships Jennifer Davis and Ryn Daniels Beijing Boston Farnham Sebastopol Tokyo Collaborating in DevOps Culture by Jennifer Davis and Ryn Daniels Copyright © 2019 Jennifer Davis and Ryn Daniels. 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.
    [Show full text]
  • Rubicon: Bounded Verification of Web Applications
    Rubicon: Bounded Verification of Web Applications The MIT Faculty has made this article openly available. Please share how this access benefits you. Your story matters. Citation Joseph P. Near and Daniel Jackson. 2012. Rubicon: bounded verification of web applications. In Proceedings of the ACM SIGSOFT 20th International Symposium on the Foundations of Software Engineering (FSE '12). ACM, New York, NY, USA, Article 60, 11 pages. As Published http://dx.doi.org/10.1145/2393596.2393667 Publisher Association for Computing Machinery (ACM) Version Author's final manuscript Citable link http://hdl.handle.net/1721.1/86919 Terms of Use Creative Commons Attribution-Noncommercial-Share Alike Detailed Terms http://creativecommons.org/licenses/by-nc-sa/4.0/ Rubicon: Bounded Verification of Web Applications Joseph P. Near, Daniel Jackson Computer Science and Artificial Intelligence Lab Massachusetts Institute of Technology Cambridge, MA, USA {jnear,dnj}@csail.mit.edu ABSTRACT ification language is an extension of the Ruby-based RSpec We present Rubicon, an application of lightweight formal domain-specific language for testing [7]; Rubicon adds the methods to web programming. Rubicon provides an embed- quantifiers of first-order logic, allowing programmers to re- ded domain-specific language for writing formal specifica- place RSpec tests over a set of mock objects with general tions of web applications and performs automatic bounded specifications over all objects. This compatibility with the checking that those specifications hold. Rubicon's language existing RSpec language makes it easy for programmers al- is based on the RSpec testing framework, and is designed to ready familiar with testing to write specifications, and to be both powerful and familiar to programmers experienced convert existing RSpec tests into specifications.
    [Show full text]
  • Why Untyped Nonground Metaprogramming Is Not (Much Of) a Problem
    NORTH- HOLLAND WHY UNTYPED NONGROUND METAPROGRAMMING IS NOT (MUCH OF) A PROBLEM BERN MARTENS* and DANNY DE SCHREYE+ D We study a semantics for untyped, vanilla metaprograms, using the non- ground representation for object level variables. We introduce the notion of language independence, which generalizes range restriction. We show that the vanilla metaprogram associated with a stratified normal oljjctct program is weakly stratified. For language independent, stratified normal object programs, we prove that there is a natural one-to-one correspon- dence between atoms p(tl, . , tr) in the perfect Herbrand model of t,he object program and solve(p(tl, , tT)) atoms in the weakly perfect Her\) and model of the associated vanilla metaprogram. Thus, for this class of programs, the weakly perfect, Herbrand model provides a sensible SC mantics for the metaprogram. We show that this result generalizes to nonlanguage independent programs in the context of an extended Hcr- brand semantics, designed to closely mirror the operational behavior of logic programs. Moreover, we also consider a number of interesting exterl- sions and/or variants of the basic vanilla metainterpreter. For instance. WC demonstrate how our approach provides a sensible semantics for a limit4 form of amalgamation. a “Partly supported by the Belgian National Fund for Scientific Research, partly by ESPRlT BRA COMPULOG II, Contract 6810, and partly by GOA “Non-Standard Applications of Ab- stract Interpretation,” Belgium. TResearch Associate of the Belgian National Fund for Scientific Research Address correspondence to Bern Martens and Danny De Schreye, Department of Computer Science, Katholieke Universiteit Leuven, Celestijnenlaan 200A. B-3001 Hevrrlee Belgium E-mail- {bern, dannyd}@cs.kuleuven.ac.be.
    [Show full text]
  • Mobile Phones and Cloud Computing
    Mobile phones and cloud computing A quantitative research paper on mobile phone application offloading by cloud computing utilization Oskar Hamrén Department of informatics Human Computer Interaction Master’s programme Master thesis 2-year level, 30 credits SPM 2012.07 Abstract The development of the mobile phone has been rapid. From being a device mainly used for phone calls and writing text messages the mobile phone of today, or commonly referred to as the smartphone, has become a multi-purpose device. Because of its size and thermal constraints there are certain limitations in areas of battery life and computational capabilities. Some say that cloud computing is just another buzzword, a way to sell already existing technology. Others claim that it has the potential to transform the whole IT-industry. This thesis is covering the intersection of these two fields by investigating if it is possible to increase the speed of mobile phones by offloading computational heavy mobile phone application functions by using cloud computing. A mobile phone application was developed that conducts three computational heavy tests. The tests were run twice, by not using cloud computing offloading and by using it. The time taken to carry out the tests were saved and later compared to see if it is faster to use cloud computing in comparison to not use it. The results showed that it is not beneficial to use cloud computing to carry out these types of tasks; it is faster to use the mobile phone. 1 Table of Contents Abstract ..................................................................................................................................... 1 Table of Contents ..................................................................................................................... 2 1. Introduction .......................................................................................................................... 5 1.1 Previous research ........................................................................................................................
    [Show full text]
  • The Machine That Builds Itself: How the Strengths of Lisp Family
    Khomtchouk et al. OPINION NOTE The Machine that Builds Itself: How the Strengths of Lisp Family Languages Facilitate Building Complex and Flexible Bioinformatic Models Bohdan B. Khomtchouk1*, Edmund Weitz2 and Claes Wahlestedt1 *Correspondence: [email protected] Abstract 1Center for Therapeutic Innovation and Department of We address the need for expanding the presence of the Lisp family of Psychiatry and Behavioral programming languages in bioinformatics and computational biology research. Sciences, University of Miami Languages of this family, like Common Lisp, Scheme, or Clojure, facilitate the Miller School of Medicine, 1120 NW 14th ST, Miami, FL, USA creation of powerful and flexible software models that are required for complex 33136 and rapidly evolving domains like biology. We will point out several important key Full list of author information is features that distinguish languages of the Lisp family from other programming available at the end of the article languages and we will explain how these features can aid researchers in becoming more productive and creating better code. We will also show how these features make these languages ideal tools for artificial intelligence and machine learning applications. We will specifically stress the advantages of domain-specific languages (DSL): languages which are specialized to a particular area and thus not only facilitate easier research problem formulation, but also aid in the establishment of standards and best programming practices as applied to the specific research field at hand. DSLs are particularly easy to build in Common Lisp, the most comprehensive Lisp dialect, which is commonly referred to as the “programmable programming language.” We are convinced that Lisp grants programmers unprecedented power to build increasingly sophisticated artificial intelligence systems that may ultimately transform machine learning and AI research in bioinformatics and computational biology.
    [Show full text]
  • Practical Reflection and Metaprogramming for Dependent
    Practical Reflection and Metaprogramming for Dependent Types David Raymond Christiansen Advisor: Peter Sestoft Submitted: November 2, 2015 i Abstract Embedded domain-specific languages are special-purpose pro- gramming languages that are implemented within existing general- purpose programming languages. Dependent type systems allow strong invariants to be encoded in representations of domain-specific languages, but it can also make it difficult to program in these em- bedded languages. Interpreters and compilers must always take these invariants into account at each stage, and authors of embedded languages must work hard to relieve users of the burden of proving these properties. Idris is a dependently typed functional programming language whose semantics are given by elaboration to a core dependent type theory through a tactic language. This dissertation introduces elabo- rator reflection, in which the core operators of the elaborator are real- ized as a type of computations that are executed during the elab- oration process of Idris itself, along with a rich API for reflection. Elaborator reflection allows domain-specific languages to be imple- mented using the same elaboration technology as Idris itself, and it gives them additional means of interacting with native Idris code. It also allows Idris to be used as its own metalanguage, making it into a programmable programming language and allowing code re-use across all three stages: elaboration, type checking, and execution. Beyond elaborator reflection, other forms of compile-time reflec- tion have proven useful for embedded languages. This dissertation also describes error reflection, in which Idris code can rewrite DSL er- ror messages before presenting domain-specific messages to users, as well as a means for integrating quasiquotation into a tactic-based elaborator so that high-level syntax can be used for low-level reflected terms.
    [Show full text]
  • INTRODUCTION to PL/1 PL/I Is a Structured Language to Develop Systems and Applications Programs (Both Business and Scientific)
    INTRODUCTION TO PL/1 PL/I is a structured language to develop systems and applications programs (both business and scientific). Significant features : v Allows Free format v Regards a program as a continuous stream of data v Supports subprogram and functions v Uses defaults 1 Created by Sanjay Sinha Building blocks of PL/I : v Made up of a series of subprograms and called Procedure v Program is structured into a MAIN program and subprograms. v Subprograms include subroutine and functions. Every PL/I program consists of : v At least one Procedure v Blocks v Group 2 Created by Sanjay Sinha v There must be one and only one MAIN procedure to every program, the MAIN procedure statement consists of : v Label v The statement ‘PROCEDURE OPTIONS (MAIN)’ v A semicolon to mark the end of the statement. Coding a Program : 1. Comment line(s) begins with /* and ends with */. Although comments may be embedded within a PL/I statements , but it is recommended to keep the embedded comments minimum. 3 Created by Sanjay Sinha 2. The first PL/I statement in the program is the PROCEDURE statement : AVERAGE : PROC[EDURE] OPTIONS(MAIN); AVERAGE -- it is the name of the program(label) and compulsory and marks the beginning of a program. OPTIONS(MAIN) -- compulsory for main programs and if not specified , then the program is a subroutine. A PL/I program is compiled by PL/I compiler and converted into the binary , Object program file for link editing . 4 Created by Sanjay Sinha Advantages of PL/I are : 1. Better integration of sets of programs covering several applications.
    [Show full text]
  • Reglas De Congo: Palo Monte Mayombe) a Book by Lydia Cabrera an English Translation from the Spanish
    THE KONGO RULE: THE PALO MONTE MAYOMBE WISDOM SOCIETY (REGLAS DE CONGO: PALO MONTE MAYOMBE) A BOOK BY LYDIA CABRERA AN ENGLISH TRANSLATION FROM THE SPANISH Donato Fhunsu A dissertation submitted to the faculty of the University of North Carolina at Chapel Hill in partial fulfillment of the requirements for the degree of Doctor of Philosophy in the Department of English and Comparative Literature (Comparative Literature). Chapel Hill 2016 Approved by: Inger S. B. Brodey Todd Ramón Ochoa Marsha S. Collins Tanya L. Shields Madeline G. Levine © 2016 Donato Fhunsu ALL RIGHTS RESERVED ii ABSTRACT Donato Fhunsu: The Kongo Rule: The Palo Monte Mayombe Wisdom Society (Reglas de Congo: Palo Monte Mayombe) A Book by Lydia Cabrera An English Translation from the Spanish (Under the direction of Inger S. B. Brodey and Todd Ramón Ochoa) This dissertation is a critical analysis and annotated translation, from Spanish into English, of the book Reglas de Congo: Palo Monte Mayombe, by the Cuban anthropologist, artist, and writer Lydia Cabrera (1899-1991). Cabrera’s text is a hybrid ethnographic book of religion, slave narratives (oral history), and folklore (songs, poetry) that she devoted to a group of Afro-Cubans known as “los Congos de Cuba,” descendants of the Africans who were brought to the Caribbean island of Cuba during the trans-Atlantic Ocean African slave trade from the former Kongo Kingdom, which occupied the present-day southwestern part of Congo-Kinshasa, Congo-Brazzaville, Cabinda, and northern Angola. The Kongo Kingdom had formal contact with Christianity through the Kingdom of Portugal as early as the 1490s.
    [Show full text]
  • A Block Design for Introductory Functional Programming in Haskell
    A Block Design for Introductory Functional Programming in Haskell Matthew Poole School of Computing University of Portsmouth, UK [email protected] Abstract—This paper describes the visual design of blocks for the learner, and to avoid syntax and type-based errors entirely editing code in the functional language Haskell. The aim of the through blocks-based program construction. proposed blocks-based environment is to support students’ initial steps in learning functional programming. Expression blocks and There exists some recent work in representing functional slots are shaped to ensure constructed code is both syntactically types within blocks-based environments. TypeBlocks [9] in- correct and preserves conventional use of whitespace. The design cludes three basic type connector shapes (for lists, tuples aims to help students learn Haskell’s sophisticated type system and functions) which can be combined in any way and to which is often regarded as challenging for novice functional any depth. The prototype blocks editor for Bootstrap [10], programmers. Types are represented using text, color and shape, [11] represents each of the five types of a simple functional and empty slots indicate valid argument types in order to ensure language using a different color, with a neutral color (gray) that constructed code is well-typed. used for polymorphic blocks; gray blocks change color once their type has been determined during program construction. I. INTRODUCTION Some functional features have also been added to Snap! [12] Blocks-based environments such as Scratch [1] and Snap! and to a modified version of App Inventor [13]. [2] offer several advantages over traditional text-based lan- This paper is structured as follows.
    [Show full text]
  • Distributed Programming with Ruby
    DISTRIBUTED PROGRAMMING WITH RUBY Mark Bates Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Capetown • Sydney • Tokyo • Singapore • Mexico City 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 the pub- lisher was aware of a trademark claim, the designations have been printed with initial Editor-in-Chief capital letters or in all capitals. Mark Taub The author and publisher have taken care in the preparation of this book, but make no Acquisitions Editor expressed or implied warranty of any kind and assume no responsibility for errors or Debra Williams Cauley omissions. No liability is assumed for incidental or consequential damages in connection Development Editor with or arising out of the use of the information or programs contained herein. Songlin Qiu The publisher offers excellent discounts on this book when ordered in quantity for bulk Managing Editor purchases or special sales, which may include electronic versions and/or custom covers Kristy Hart and content particular to your business, training goals, marketing focus, and branding Senior Project Editor interests. For more information, please contact: Lori Lyons U.S. Corporate and Government Sales Copy Editor 800-382-3419 Gayle Johnson [email protected] Indexer For sales outside the United States, please contact: Brad Herriman Proofreader International Sales Apostrophe Editing [email protected] Services Visit us on the web: informit.com/ph Publishing Coordinator Kim Boedigheimer Library of Congress Cataloging-in-Publication Data: Cover Designer Bates, Mark, 1976- Chuti Prasertsith Distributed programming with Ruby / Mark Bates.
    [Show full text]
  • Practical Ruby Projects: Practical Ruby Projects Ideas for the Eclectic Programmer
    CYAN YELLOW MAGENTA BLACK PANTONE 123 C BOOKS FOR PROFESSIONALS BY PROFESSIONALS® THE EXPERT’S VOICE® IN OPEN SOURCE Companion eBook Available Practical Ruby Projects: Projects Ruby Practical Ideas for the Eclectic Programmer Dear Reader, You’ve learned the basics of Ruby, and you’re ready to move on to the next level— trying out advanced techniques, mastering best practices, and exploring Ruby’s full potential. With this book you’ll learn by experience while you tackle an exciting series of varied but always practical programming projects. What is an eclectic programmer, you ask? He or she is an inquisitive thinker Practical who likes to play around with new concepts, a person who is project-oriented and enjoys coding, a person who doesn’t mind some technical depth folded in with creative excursions, and a person who is always looking for fresh ideas. This book is a little different from other computer books. It is meant to be entertaining, exciting, and intellectually challenging. Inside you’ll find a collec- tion of diverse projects, ranging from the creative to the practical, written as a nod to all the great Rubyists I’ve been privileged to know. Each chapter dives into Ruby Projects new topics and approaches meant to exercise your programming muscles. You’ll start by building a cross-platform music environment, progress to drawing animations using scalable vector graphics, and then move on to prac- tical problem solving using simulation. In addition, you’ll implement your own turn-based strategy game and build a Mac-native RubyCocoa interface to it.
    [Show full text]
  • Theine2 Documentation Release Latest
    theine2 Documentation Release latest Dec 06, 2019 Contents 1 Installing 3 2 Upgrading 5 3 Using 7 4 Configuration 9 4.1 base_port and max_port.........................................9 4.2 min_free_workers............................................9 4.3 spawn_parallel..............................................9 4.4 silent................................................... 10 5 Speed up Theine 11 5.1 Tell Theine to use CRuby for the client................................. 11 6 Using with Foreman 13 7 Using with Docker 15 8 How it works 17 i ii theine2 Documentation, Release latest Theine is a Rails application pre-loader designed to work on JRuby. It is similar to Zeus, Spring and Spork. The problem with Zeus and Spring is that they use fork which doesn’t work on JRuby. An example: time rails runner"puts Rails.env" 48.31s user 1.96s system 242% cpu 20.748 total # normal time theine runner"puts Rails.env" 0.12s user 0.02s system 32% cpu 0.449 total # Theine Contents 1 theine2 Documentation, Release latest 2 Contents CHAPTER 1 Installing You need to install screen on your system. For example on Ubuntu: sudo apt-get install screen Then install the gem. gem install theine2 3 theine2 Documentation, Release latest 4 Chapter 1. Installing CHAPTER 2 Upgrading If you want to use CRuby for the client, you will probably need to re-run theine_set_ruby after upgrading. 5 theine2 Documentation, Release latest 6 Chapter 2. Upgrading CHAPTER 3 Using Start up the theine server in the root of your Rails project: theine_server or theine_start for a detached
    [Show full text]