Delightful lessons for dedicated programmers

Ruby QuickRefTable of Contents Language General Tips These are tips I’ve given over and over and over and over… Use 2 space indent, no tabs. See for more. General Syntax Rules Comments start with a pound/sharp (#) character and go to EOL. Reserved Words alias and BEGIN begin break case class def defined? Types Basic types are numbers, strings, ranges, regexen, symbols, arrays, and hashes. Numbers 1231_234123.451.2e-30xffff 0b01011 0377 ? Strings In all of the %() cases below, you may use any matching characters or any single character for delimiters. %[], %!! 'no interpolation'"#{interpolation}, and backslashes\n"%q(no interpolation)%Q(interpolation and backslashes)%(interpolation and backslashes)`echo command interpretation with interpolation and backslashes`%x(echo command interpretation with interpolation and backslashes) Backslashes: Here Docs: Encodings: Waaaay too much to cover here. Symbols Internalized String. Ranges 1..101...10'a'..' Regexen "r"

Learn Web Development with the Ruby on Rails TutorialMichael Hartl Contents Foreword My former company (CD Baby) was one of the first to loudly switch to Ruby on Rails, and then even more loudly switch back to PHP (Google me to read about the drama). This book by Michael Hartl came so highly recommended that I had to try it, and the Ruby on Rails Tutorial is what I used to switch back to Rails again. Though I’ve worked my way through many Rails books, this is the one that finally made me “get” it. The linear narrative is such a great format. Enjoy! Derek Sivers (sivers.org) Founder, CD Baby Acknowledgments The Ruby on Rails Tutorial owes a lot to my previous Rails book, RailsSpace, and hence to my coauthor Aurelius Prochazka. I’d like to acknowledge a long list of Rubyists who have taught and inspired me over the years: David Heinemeier Hansson, Yehuda Katz, Carl Lerche, Jeremy Kemper, Xavier Noria, Ryan Bates, Geoffrey Grosenbach, Peter Cooper, Matt Aimonetti, Gregg Pollack, Wayne E. About the author Copyright and license 1.1 Introduction

Rubynorte | Conferência de Ruby no Porto, Portugal.Best tips and practices from Ruby expertsAs you work with Ruby a lot and develop applications, you will start using more and more components, like fast RESTful APIs or any other frameworks. In that situation you need to think about separating responsibilities and business logic. For example, if you are using Ruby on Rails, you should start using ActiveRecord and keep all rake tasks outside the Rails. Let’s now imagine you want to create a new restful API using Grape, but you don’t want to end up replicating models. What can you do? One way to do this is to move your models and core tasks to a Gem so it can be decoupled and used anywhere. You can use Bundler to initiate a new Gem with the command: bundle gem core. ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── core.gemspec └── lib ├── core │ └── version.rb └── core.rb These files contain most of the business logic, and we need to move them to a separate Gem so they can be used outside Rails applications: That’s it.

Ruby Koans OnlineRuby/2013-01-22-book-problems.md at master · Duke-PL-Course/RubyRuby ProgrammingRuby is an interpreted, object-oriented programming language. Its creator, Yukihiro Matsumoto, a.k.a “Matz,” released it to the public in 1995. Its history is covered here. Its many features are listed here. The book is currently broken down into several sections and is intended to be read sequentially. Getting started will show how to install and get started with Ruby in your environment. Table of Contents[edit] Getting started[edit] Overview Installing Ruby Ruby editors Notation conventions Interactive Ruby Mailing List FAQ Basic Ruby[edit] Hello world Strings Alternate quotes Here documents Encoding Introduction to objects Ruby basics Data types — numbers, strings, hashes and arrays Writing methods Classes and objects Exceptions Ruby Semantic reference[edit] See also some rdoc documentation on the various keywords. Built in Classes[edit] This is a list of classes that are available to you by default in Ruby. Available Standard Library Modules[edit] Other Libraries[edit] Database Interface Modules Unit testing

voxdolo/decent_exposureRyan Angilly — Dynamically adding class methods in RubyEven though there is technically no such thing as a class method in Ruby, I’m going to call them that for the sake of clarity. When I say class method, I mean something like this: class A class << self def yo "wassup" end end end A.yo #=> "wassup" Every now and then, you may want to dynamically generate these things. Thanks to instance_eval and define_method, dynamically defining methods in Ruby is trivial, but these operate in what someone coming from Java or C++ would call the instance context. Take the following example: class A class << self def create_method(name) define_method(name) { puts "Nice! The define_method creates a method that is only accessible on instances of the class, not a class method. class A class << self def create_method(name) self.class.instance_eval do define_method(name) { puts "Nice! Great success! class A class << self def create_method(name) self.class.instance_eval do define_method(name) { puts "Nice! What? "1".class.mine # prints out "Nice! Yeah. Simple.

Metaprogramming in Ruby: It’s All About the SelfNovember 15th, 2009 After writing my last post on Rails plugin idioms, I realized that Ruby metaprogramming, at its core, is actually quite simple. It comes down to the fact that all Ruby code is executed code–there is no separate compile or runtime phase. All five of these snippets define a Person.species that returns Homo Sapien. These snippets all define a method called name on the Person class. First, it is important to understand how Ruby’s metaclass works. Person is an instance of Class, so any methods added to Class are available on Person as well. What’s going on here is that we’re adding the speak method to matz‘s metaclass, and the matz object inherits from its metaclass and then Object. In fact, matz‘s “class” is its invisible metaclass. At this point in other articles on this topic, you’re probably struggling to keep all of the details in your head; it seems as though there are so many rules. Here, we are adding the name method to the Person class.

Ruby Quiz - MUD Client (#45)MUD Client (#45) Sy has been searching for a Ruby scriptable MUD client via Ruby Talk and so far, there hasn't been many helpful answers posted. Let's generate some. This week's Ruby Quiz is to create a basic MUD client that must be scriptable in the Ruby programming language. That's pretty vague, so let me see if I can answer the questions I'm sure at least some of you still have. What is a MUD? MUD stands for Multi-User Dungeon/Dimension, depending on who you ask. > lookSacred Grove You are standing in the legendary resting place of The Dagger in The Stone.Many have tried to free the mystical blade before, but none were worthy. You can see the Castle of Evil to the west. What's here: The Dagger in The Stone >look daggerThe all-powerful blade begs to be stolen! >get daggerYou take the dagger. >equip daggerYou are now the most dangerous warrior in the kingdom! >westThe Gates of Castle of Evil A very big, very black, very evil castle. What's here: Grog, Castle Guardian The MUD Connector The MUD FAQ