Gosu, 2D game development library Ruby on Rails Guides Ruby core classes aren't thread safe | Jesse Storimer's Blog A few days I shared a quote on Twitter: > Ruby Arrays aren't thread-safe, [...] MRI's threading implementation accidentally makes them thread-safe. It saw a bunch of retweets and discussion, but I daresay that the nuances of that statement were lost on a lot of developers. That's a big question, and I think the answer lies in education. Let's dig in with an example. Here's a very simple inventory tracking class: class Inventory def initialize(stock_levels) @stock = stock_levels end def decrease(item) @stock[item] -= 1 def [](item) @stock[item] It's trivially simple. inventory = Inventory.new(:tshirt => 200, :pants => 340, :hats => 4000) inventory.decrease(:hats) inventory.decrease(:pants) Now let me ask you this: is this thread-safe? Let's exercise this code to find out. 4000.times do puts inventory[:hats] Running this code on MRI 1.9.3, the answer is, predictably, 0. Now let's exercise the code again, with threads this time. threads = Array.new 40.times do threads << Thread.new do 100.times do 400.times do
Ruby on Rails Guides Ruby on Rails Tutorial: Learn Rails by Example book and screencasts by Michael Hartl | Static Pages Michael 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 3.1 Static pages
The Ruby Programming Language Learn Web Development with the Ruby on Rails Tutorial Michael 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). 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 Michael Hartl is the author of the Ruby on Rails Tutorial, the leading introduction to web development with Ruby on Rails. Copyright and license Welcome to the Ruby on Rails Tutorial.
The Best Way to Learn Rails I come from a PHP background, but these days, I'm a full-time Rails developer. The difficulty for most people who make the switch lies in the learning curve that’s involved. Once you've become proficient in a language or framework, switching to a new one feels like an unnecessary (and time-consuming) challenge. However, learning Ruby and Rails is actually pretty easy! This article details a full lesson plan that will get you up and running in no time! You might think learning Ruby is the most important step, and this is probably the part where everyone stops learning and just sticks with their current framework. Work through the Try Ruby exercises. The most recommended tool for dipping into Ruby's syntax is the Try Ruby website. Once you’ve worked through these exercises a couple of times, you'll have a solid base. Run gem install rails to install Rails. If you want to learn Rails, you’ll of course need to install it on your machine. Next, you need to install Rails. Great!
Four Guidelines That I Feel Have Improved My Code I have been thinking a lot about isolation, dependencies and clean code of late. I know there is a lot of disagreement with people vehemently standing in both camps. I certainly will not say either side is right or wrong, but what follows is what I feel has improved my code. I post it here to formalize some recent thoughts and, if I am lucky, get some good feedback. Before I rush into the gory details, I feel I should mention that I went down this path, not as an architecture astronout, but out of genuine pain in what I was working on. My models were growing large. I started watching Gary Bernhardt’s Destroy All Software screencasts. On top of DAS, I started reading everything I could on the subject of growing software, clean code and refactoring. I was literally prowling about like a lion, looking for the next book I could devour. Over the past few months as I have tried to write better code, I have definitely learned a lot. Guideline #1. The problem is context. Create More Classes