Ruby for Rails

Total Page:16

File Type:pdf, Size:1020Kb

Ruby for Rails Ruby for Rails Ruby for Rails RUBY TECHNIQUES FOR RAILS DEVELOPERS DAVID A. BLACK MANNING Greenwich (74° w. long.) For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact: Special Sales Department Manning Publications Co. 209 Bruce Park Avenue Fax:(203) 661-9018 Greenwich, CT 06830 email: [email protected] ©2006 Manning Publications. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books they publish printed on acid-free paper, and we exert our best efforts to that end. Manning Publications Co. Copyeditor: Liz Welch 209 Bruce Park Avenue Typesetter: Gordan Salinovic Greenwich, CT 06830 Cover designer: Leslie Haimes ISBN 1932394699 Printed in the United States of America 12345678910–VHG–10 090807 06 for n in nephews + nieces which is to say: Annie, David, Elizabeth, Rebecca, and Robert, with all my love. You’re all absolutely amazing, and I adore you. brief contents PART ITHE RUBY/RAILS LANDSCAPE ...........................1 1 ■ How Ruby works 3 2 ■ How Rails works 33 3 ■ Ruby-informed Rails development 67 PART II RUBY BUILDING BLOCKS ................................93 4 ■ Objects and variables 95 5 ■ Organizing objects with classes 121 6 ■ Modules and program organization 154 7 ■ The default object (self) and scope 177 8 ■ Control flow techniques 206 PART III BUILT-IN CLASSES AND MODULES ...............231 9 ■ Built-in essentials 233 10 ■ Scalar objects 257 11 ■ Collections, containers, and enumerability 277 vii viii BRIEF CONTENTS 12 ■ Regular expressionsand regexp-based string operations 312 13 ■ Ruby dynamics 337 PART IV RAILS THROUGH RUBY, RRRRRRRRIRUBY THROUGH RAILS ............................. 369 14 ■ (Re)modeling the R4RMusic application universe 371 15 ■ Programmatically enhancing ActiveRecord models 392 16 ■ Enhancing the controllers and views 422 17 ■ Techniques for exploring the Rails source code 455 appendix ■ Ruby and Rails installation and resources 471 contents foreword xix preface xxi acknowledgments xxiii about this book xxvi about the cover illustration xxxii PART 1THE RUBY/RAILS LANDSCAPE ...........................1 How Ruby works 3 1 1.1 The mechanics of writing a Ruby program 4 Getting the preliminaries in place 5 ■ A Ruby literacy bootstrap guide 5 ■ A brief introduction to method calls and Ruby objects 7 Writing and saving a sample program 8 ■ Feeding the program to Ruby 9 ■ Keyboard and file input 11 ■ One program, multiple files 14 1.2 Techniques of interpreter invocation 15 Command-line switches 16 ■ A closer look at interactive Ruby interpretation with irb 20 1.3 Ruby extensions and programming libraries 21 Using standard extensions and libraries 21 ■ Using C extensions 22 ■ Writing extensions and libraries 23 ix x CONTENTS 1.4 Anatomy of the Ruby programming environment 24 The layout of the Ruby source code 24 ■ Navigating the Ruby installation 25 ■ Important standard Ruby tools and applications 27 1.5 Summary 31 How Rails works 33 2 2.1 Inside the Rails framework 34 A framework user’s–eye view of application development 35 Introducing the MVC framework concept 36 Meet MVC in the (virtual) flesh 37 2.2 Analyzing Rails’ implementation of MVC 38 2.3 A Rails application walk-through 41 Introducing R4RMusic, the music-store application 42 Modeling the first iteration of the music-store domain 43 Identifying and programming the actions 50 ■ Designing the views 53 ■ Connecting to the application 58 2.4 Tracing the lifecycle of a Rails run 59 Stage 1: server to dispatcher 61 ■ Stage 2: dispatcher to controller 62 ■ Stage 3: performance of a controller action 62 ■ Stage 4: the fulfillment of the view 65 2.5 Summary 65 Ruby-informed Rails development 67 3 3.1 A first crack at knowing what your code does 69 Seeing Rails as a domain-specific language 70 ■ Writing program code with a configuration flavor 73 ■ YAML and configuration that’s actually programming 75 3.2 Starting to use Ruby to do more in your code 77 Adding functionality to a controller 79 ■ Deploying the Rails helper files 80 ■ Adding functionality to models 82 3.3 Accomplishing application-related skills and tasks 85 Converting legacy data to ActiveRecord 85 The irb-based Rails application console 89 3.4 Summary 90 CONTENTS xi PART 2RUBY BUILDING BLOCKS .................................93 Objects and variables 95 4 4.1 From “things” to objects 96 Introducing object-oriented programming 97 ■ I, object! 98 Modeling objects more closely: the behavior of a ticket 103 4.2 The innate behaviors of an object 108 Identifying objects uniquely with the object_id method 109 Querying an object’s abilities with the respond_to? method 110 Sending messages to objects with the send method 111 4.3 Required, optional, and default-valued arguments 112 Required and optional arguments 112 ■ Default values for arguments 113 ■ Order of arguments 114 4.4 Local variables and variable assignment 115 Variable assignment in depth 117 ■ Local variables and the things that look like them 119 4.5 Summary 120 Organizing objects with classes 121 5 5.1 Classes and instances 122 A first class 123 ■ Instance variables and object state 126 5.2 Setter methods 130 The equal sign (=) in method names 131 ActiveRecord properties and other =-method applications 133 5.3 Attributes and the attr_* method family 136 Automating the creation of attribute handlers 137 ■ Two (getter/ setter) for one 138 ■ Summary of attr_* methods 139 5.4 Class methods and the Class class 140 Classes are objects too! 140 ■ When, and why, to write a class method 141 ■ Class methods vs. instance methods, clarified 143 The Class class and Class.new 144 5.5 Constants up close 145 Basic usage of constants 145 ■ Reassigning vs. modifying constants 146 xii CONTENTS 5.6 Inheritance 148 Inheritance and Rails engineering 149 ■ Nature vs. nurture in Ruby objects 151 5.7 Summary 153 Modules and program organization 154 6 6.1 Basics of module creation and use 155 A module encapsulating “stack-like-ness” 157 ■ Mixing a module into a class 158 ■ Leveraging the module further 160 6.2 Modules, classes, and method lookup 163 Illustrating the basics of method lookup 163 ■ Defining the same method more than once 166 ■ Going up the method search path with super 168 6.3 Class/module design and naming 170 Mix-ins and/or inheritance 171 ■ Modular organization in Rails source and boilerplate code 173 6.4 Summary 176 The default object (self) and scope 177 7 7.1 Understanding self, the current/default object 179 Who gets to be self, and where 179 ■ Self as default receiver of messages 184 ■ Instance variables and self 186 7.2 Determining scope 188 Global scope and global variables 188 ■ Local scope 191 Scope and resolution of constants 194 7.3 Deploying method access rules 197 Private methods 197 ■ Private methods as ActionController access protection 199 ■ Protected methods 201 7.4 Writing and using top-level methods 203 Defining a top-level method 203 ■ Predefined (built-in) top-level methods 204 7.5 Summary 205 Control flow techniques 206 8 8.1 Conditional code execution 207 The if keyword and friends 208 ■ Conditional modifiers 211 Case statements 211 CONTENTS xiii 8.2 Repeating actions with loops 215 Unconditional looping with the loop method 215 Conditional looping with the while and until keywords 216 Looping based on a list of values 218 8.3 Code blocks, iterators, and the yield keyword 219 The basics of yielding to a block 219 ■ Performing multiple iterations 222 ■ Using different code blocks 223 More about for 223 8.4 Error handling and exceptions 225 Raising and rescuing exceptions 225 ■ Raising exceptions explicitly 227 ■ Creating your own exception classes 228 8.5 Summary 230 PART 3BUILT-IN CLASSES AND MODULES ...................231 Built-in essentials 233 9 9.1 Ruby’s literal constructors 234 9.2 Recurrent syntactic sugar 236 Special treatment of += 237 9.3 Methods that change their receivers (or don’t) 238 Receiver-changing basics 239 ■ bang (!) methods 240 Specialized and extended receiver-changing in ActiveRecord objects 241 9.4 Built-in and custom to_* (conversion) methods 242 Writing your own to_* methods 243 9.5 Iterators reiterated 244 9.6 Boolean states, Boolean objects, and nil 245 True and false as states 246 ■ true and false as objects 248 The special object nil 249 9.7 Comparing two objects 251 Equality tests 251 ■ Comparisons and the Comparable module 252 9.8 Listing an object’s methods 253 Generating filtered and selective method lists 254 9.9 Summary 255 xiv CONTENTS Scalar objects 257 10 10.1 Working with strings 258 String basics 258 ■ String operations 260 Comparing strings 265 10.2 Symbols and their uses 267 Key differences between symbols and strings 267 Rails-style method arguments, revisited 268 10.3 Numerical objects 270 Numerical classes 270 ■ Performing arithmetic operations 271 10.4 Times and dates 272 10.5 Summary 275 Collections, containers, and enumerability 277 11 11.1 Arrays
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]
  • 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 16 02 03 General Information WiFi Access Network: ruby Password: rubyconf Registration Speaker Lounge Monday 7:30AM-6:00PM Monday 9:00AM-5:00PM Tuesday 8:30AM-7:00PM Tuesday 10:00AM-5:00PM Wednesday 8:30AM-5:30PM Wednesday 10:00AM-3:00PM T-Shirt Pickup Lost and Found Located at Registration. Located at Registration. Monday 12:10PM-1:20PM Contact Us Tuesday 12:00PM-5:30PM [email protected] @rubyconf Wednesday 12:00PM-5:30PM 04 05 Meet the Team Barrett Clark Marty Haught Program Chair Program Chair Developer, speaker, author, and organizer. In addition to Engineering director at Fastly. Marty is heavily involved in the organizing RubyConf, he also co-organizes RailsCamp South. software community, most notably as an organizer of Barrett works at The Container Store on their e-commerce site RailsConf and RubyConf. Beyond his love for the outdoors, and related applications. Outside of work he enjoys food and music, Marty is busy raising his two children with his volunteering at his children's activities, as well as cooking and lovely wife and enjoying life. craft cocktails. Abigail Phoenix Heather Johnson Executive Administrator Event Producer Abigail (Abby) Phoenix is the Executive Administrator of Ruby Heather is the Event Producer at Ruby Central. After years of Central, which means she gets to reply to all of your lovely planning and producing trade shows, she decided to shift her emails and write the checks, which are her two favorite things focus to planning conferences and events.
    [Show full text]
  • Sponsorship Prospectus
    Sponsorship Prospectus November 8-10, 2021 650+ in person and countless virtual attendees can expect 4 keynotes, dozens of talks, our job fair and exposure to your brand! RubyConf, the first and most enduring Ruby conference, has been gathering Rubyists from around the world together since 2001. This year, we're organizing our very first hybrid event! Two decades on, we're still focused on fostering the Ruby programming language and the incredible community that has sprung up around it and giving Rubyists space to discuss emerging ideas, collaborate, and socialize. With those same goals in mind, this year's RubyConf will be held in person, but can also be enjoyed from the comfort of participants' own homes from Nov 8-10, 2021! With the transition to a hybrid event, our sponsorship offerings have also been thoughtfully adapted, so we encourage you to read through them carefully. We're excited to chat with you about how we can help your organization achieve your goals at RubyConf 2021! Benefits of Sponsoring and Attending RubyConf Interact with Rubyists from around the world Learn from and engage with the field's top Ruby developers, including Yukihiro Matsumoto ("Matz"), the creator of the Ruby language Enjoy detailed talks about exciting new projects in the Ruby community Meet and recruit Ruby developers to join your team! Directly aid Ruby Central, the community-funded organization that funds the Ruby ecosystem and infrastructure through: Our management and oversight of RubyGems.org Our support of the continued development and maintenance of the Ruby programming language, via grants made to Ruby Association Join the growing roster of RubyConf Sponsor alumni including: Braintree, Shopify, Engine Yard, Scout APM, Cedarcode, Michelada, and more! Our last conference We launched RubyConf 2020, our first-ever virtual event, last fall.
    [Show full text]
  • The Ruby Way: Solutions and Techniques in Ruby Programming
    Praise for The Ruby Way, Third Edition “Sticking to its tried and tested formula of cutting right to the techniques the modern day Rubyist needs to know, the latest edition of The Ruby Way keeps its strong reputation going for the latest generation of the Ruby language.” Peter Cooper Editor of Ruby Weekly “The authors’ excellent work and meticulous attention to detail continues in this lat- est update; this book remains an outstanding reference for the beginning Ruby pro- grammer—as well as the seasoned developer who needs a quick refresh on Ruby. Highly recommended for anyone interested in Ruby programming.” Kelvin Meeks Enterprise Architect Praise for Previous Editions of The Ruby Way “Among other things, this book excels at explaining metaprogramming, one of the most interesting aspects of Ruby. Many of the early ideas for Rails were inspired by the first edition, especially what is now Chapter 11. It puts you on a rollercoaster ride between ‘How could I use this?’ and ‘This is so cool!’ Once you get on that roller- coaster, there’s no turning back.” David Heinemeier Hansson Creator of Ruby on Rails, Founder at Basecamp “The appearance of the second edition of this classic book is an exciting event for Rubyists—and for lovers of superb technical writing in general. Hal Fulton brings a lively erudition and an engaging, lucid style to bear on a thorough and meticulously exact exposition of Ruby. You palpably feel the presence of a teacher who knows a tremendous amount and really wants to help you know it too.” David Alan Black Author of The Well-Grounded Rubyist “This is an excellent resource for gaining insight into how and why Ruby works.
    [Show full text]
  • Apache Thrift and Ruby by Randy Abernethy
    Apache Thrift and Ruby By Randy Abernethy In this article, excerpted from The Programmer’s Guide to Apache Thrift, we will install Apache Thrift support for Ruby and build a simple Ruby RPC client and server. Ruby is a flexible programming language used for systems administration scripting, web programming and general purpose coding. Many important DevOps tools are written in Ruby, such as Puppet, Chef, and Vagrant. Ruby is behind one of the most popular web frameworks, Rails and Ruby is also a key language in many test frameworks, including RSpec and Cucumber. Ruby provides the best features of Perl’s string processing and adds objects, functional programming features, reflection and automatic memory management. When combined with Apache Thrift Ruby becomes an effective RPC service platform as well as an incredibly versatile language for RPC service mocking and testing. To build Apache Thrift clients and servers in Ruby we will need to install the Apache Thrift IDL Compiler and the Apache Thrift Ruby library package. In Ruby packages are called gems and can be installed using the RubyGems “gem” package manager. There are over 90,000 Ruby gems hosted on RubyGems.org, the central repository for publicly available Ruby packages. A search for “thrift” on the RubyGems.org site produces a list of over 30 gems, including the official Apache Thrift Ruby library, which is named “thrift.” If you have a working Ruby installation, it is fairly easy to install support for Apache Thrift. Here’s an example: $ sudo gem install thrift Building native extensions. This could take a while..
    [Show full text]
  • The Druby Book(2012).Pdf
    What Readers Are Saying About The dRuby Book The dRuby Book is a fantastic introduction to distributed programming in Ruby for all levels of users. The book covers all aspects of dRuby, including the principles of distributed programming and libraries and techniques to make your work easier. I recommend this book for anyone who is interested in distributed program- ming in Ruby and wants to learn the basics all the way to advanced process coordination strategies. ➤ Eric Hodel Ruby committer, RDoc and RubyGems maintainer dRuby is the key component that liberates Ruby objects from processes and machine platforms. Masatoshi himself explains its design, features, case studies, and even more in this book. ➤ Yuki “Yugui” Sonoda Ruby 1.9 release manager dRuby naturally extends the simplicity and power Ruby provides. Throughout this book, Rubyists should be able to enjoy a conversation with dRuby that makes you feel as if your own thoughts are traveling across processes and networks. ➤ Kakutani Shintaro RubyKaigi organizer, Ruby no Kai Any programmer wanting to understand concurrency and distributed systems using Ruby should read this book. The explanations and example code make these topics approachable and interesting. ➤ Aaron Patterson Ruby and Ruby on Rails core committer A fascinating and informative look at what is classically a total pain in the neck: distributed object management and process coordination on a single machine or across a network. ➤ Jesse Rosalia Senior software engineer The dRuby Book Distributed and Parallel Computing with Ruby Masatoshi Seki translated by Makoto Inoue The Pragmatic Bookshelf Dallas, Texas • Raleigh, North Carolina Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks.
    [Show full text]
  • 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.
    [Show full text]
  • Ruby 1.9.X Web Servers Booklet
    The Ruby 1.9.x Web Servers Booklet Ruby 1.9.x Web Servers Booklet A SURVEY OF ARCHITECTURAL CHOICES & ANALYSIS OF RELATIVE PERFORMANCE MUHAMMAD A. ALI <oldmoe> http://oldmoe.blogspot.com http://github.com/oldmoe [email protected] A Survey of Architectural Choices & Analysis of Relative Performance 1/60 The Ruby 1.9.x Web Servers Booklet Abstract This survey looks at different Ruby web servers and attempts to rationalize their architectural choices. It tries to build a background of best practices in building web servers and compares those to what is found in the Ruby servers being surveyed. Finally benchmarking results are presented and compared to initial expectations. A Survey of Architectural Choices & Analysis of Relative Performance 2/60 The Ruby 1.9.x Web Servers Booklet About the Author Muhammad A. Ali, A.K.A oldmoe, is a software developer from Alexandria, Egypt. He has been writing software professionally for more than nine years now. He authored the NeverBlock, Reactor and MySQLPlus Ruby libraries. He loves to code in Ruby and JavaScript. While not coding he enjoys looking at code written by the likes of _Why the Lucky Stiff and Marc-André Cournoyer. A Survey of Architectural Choices & Analysis of Relative Performance 3/60 The Ruby 1.9.x Web Servers Booklet Disclaimer This survey is rather limited in its scope as it focuses solely on the Ruby 1.9.x series. It does not attempt to cover Ruby 1.8.x, Ruby EE or JRuby. The version used for the tests presented in this document is 1.9.1.
    [Show full text]
  • Package Management with Rubygems
    Extracted from: Programming Ruby The Pragmatic Programmers’ Guide Second Edition This PDF file contains pages extracted from Programming Ruby, published by The Pragmatic Bookshelf. For more information, visit http://www.pragmaticbookshelf.com. Note: This extract contains some colored text. is available only in online versions of the books. The printed versions are black and white. Pagination might vary between the online and printer versions; the content is otherwise identical. Copyright © 2004 The Pragmatic Programmers, LLC. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher. Chad Fowler is a leading figure in the Ruby community. He’s on the board of Ruby Central, Inc. He’s one of the organizers of RubyConf. And he’s one of the writers of RubyGems. All this makes him uniquely qualified to write this chapter. Chapter 17 Package Management with RubyGems RubyGems is a standardized packaging and installation framework for libraries and applications, making it easy to locate, install, upgrade, and uninstall Ruby packages. It provides users and developers with four main facilities. 1. A standardized package format, 2. A central repository for hosting packages in this format, 3. Installation and management of multiple, simultaneously installed versions of the same library, 4. End-user tools for querying, installing, uninstalling, and otherwise manipulating these packages. Before RubyGems came along, installing a new library involved searching the Web, downloading a package, and attempting to install it—only to find that its dependencies haven’t been met.
    [Show full text]
  • 12 Years of Iphone – a Developer's Perspective
    12 Years of iPhone – A Developer’s Perspective Adrian Kosmaczewski 2019-04-21 This is the talk that I gave in the 4th MCE Conference in Warsaw, Poland, on May 8th, 2017 (conference organized by Polidea) and (with updates) at UIKonf on May 15th, 2018 and at NSConfArg on April 20th, 2019. • Introduction • 2007 • 2008 • 2009 • 2010 • 2011 • 2012 • 2013 • 2014 • 2015 • 2016 • 2017 • 2018 And Beyond • Slides • Video Introduction The iPhone celebrates its 12th anniversary this year. From a historical point of view, it had a tremendous impact in the industry and the careers of those involved in mobile application software development. At some point in my career, I was a .NET developer, and then one day I told myself that I wanted to write Objective-C for a living. This is how I started my career in this galaxy. This is how I got here. I could have chosen Windows Mobile. I could have chosen BlackBerry. I chose the iPhone. I started working on my first iPhone application back in July 2008, and back then everybody, and I mean every single person in the industry around me, told me that I was completely crazy and/or stupid for losing my time with a device nobody would buy. I have not stopped writing iOS applications ever since, even though lately I’ve been spending quite a bit of time around Android. 1 The iPhone turned out to be a far, far bigger platform than any of us could ever imagine. In this talk I am going to take you in a trip back in time, to remember frameworks, people, companies, events and projects that have marked our craft in the past decade.
    [Show full text]
  • Humble Little Ruby Book.Pdf
    M R . N E I G H B O R L Y ' S HUMBLE LITTLE RUBY BOOK M R . N E I G H B O R L Y ' S HUMBLE LITTLE RUBY BOOK Jeremy McAnally All content ©2006 Jeremy McAnally. All Right Reserved. That means don't copy it. For my wife, friends, and family, thank you for the support and food. Mostly the food. TABLE OF CONTENTS What'chu talkin' 'bout, Mister? 4 0 What Is Ruby Anyhow? 4 Installing Ruby 6 Windows 6 · Mac OS X 6 · Linux 7 Let's try her out! 8 Welcome to Ruby 10 1 Basic Concepts of Ruby 10 Types in Ruby 11 Strings 11 · Numbers 13 Collections 14 The Range 15 · The Array 16 · The Hash 20 Variables and the Like 23 Break it down now! 27 2 Methods 27 Defining Methods 28 · Using Methods 30 Blocks and Proc Objects 31 Block Basics 31 · Procs and Blocks 33 · Building Blocks 35 Your objects lack class! 36 Defining Classes 37 · Methods and Variables 38 · Attributes 40 · Access Control 41 · Class Scoped Objects 42 Modules 44 Creating Modules 44 Files 46 Hustle and flow (control) 48 3 Conditionals 48 The if statement 48 · The case Statement 51 Loops 53 Conditional Loops 53 · Iterating Loops and Blocks 54 · Statement Modifiers 55 · Controlling Loops 56 Exceptions 58 Handling Exceptions 58 · Raising Exceptions 61 · My Own Exception 62 · Throw and Catch 62 The System Beneath 64 4 Filesystem Interaction 64 Writing to a file 66 · More file operations 67 Threads and Forks and Processes, Oh My! 68 Ruby thread basics 68 · Controlling threads 70 · Getting information from threads 71 · Processes, the other way to do stuff 72 For the Environment! 73 Environment variables and the like 73 · The command line and you 73 · Ruby and its little corner of your computer 74 Win32 and Beyond 75 API 75 · The Registry 77 · OLE Automation 79 Looking Beyond Home 83 5 Networking and the Web 83 Socket Programming 83 · HTTP Networking 86 Other Network Services 92 · Web Services 95 It's Like Distributed or Something..
    [Show full text]