sitepoint.com sitepoint.com

Rspec-Given

Testing is a Given I have played with a lot of testing frameworks. We Rubyists are forever obsessing about our testing. Be it testing like Usain Bolt or the TSA, either way, we be testing. And that is a very good thing. I subscribe heavily to making my code as readable and understandable as possible. I, for one, read more code than I write. The first place I always look is the tests. The integration and functional tests give me the...

sitepoint.com sitepoint.com

Basecamp-like Subdomains with Devise

Building authentication for applications is a run of the mill task we have all encountered at some point or another. In the past, most developers would have reached into their tool belt and pulled out restful authentication. Lately, a new kid on the block has been stealing a lot of thunder where authentication is concerned, and with good reason. Devise provides a complete authentication solution. Views, mailers and a host of common...

sitepoint.com sitepoint.com

Rack for Middlewares

In the previous article we thinly disguised a Rack tutorial as a comparison of PHP and Ruby. The aim of the article was to point out that most PHP developers start out on a pretty well thought out learning trail. We head to “hello world”, breeze by some basic HTML interlaced with PHP, ascend to separating views and business logic then end up at using a suitable community driven framework. However, when it comes to learning...

sitepoint.com sitepoint.com

Getting to Grips with Blocks II

In the last article we had a whistle stop tour of blocks. How they are defined, what purposes they serve and the differences between various Ruby versions. It was all very academic. But practically what benefit do we actually get from blocks. What makes them such a powerful tool for Ruby developers. Procs and Lambdas Before we get into some useful examples of blocks, we have to discuss Proc and lambda. These two allow you to define a...

sitepoint.com sitepoint.com

Getting to Grips with Blocks

When making the switch to Ruby from a PHP background, one of the grayest areas for me was blocks. Blocks are everywhere in Ruby and not having a good understanding of them will stall your learning past the “novice” stage. When you first start out with Ruby you will inevitably use blocks exclusively for iteration. Hello Blocks 3.times {|n| puts "Printed #{n} times" } The code above must be the “hello...