Don’t Run This Code

If you execute this line of code within the United States you may be in violation of the law:
PLAIN TEXT
RUBY:

puts %w{ 011 371 021 002

         235 164 343 133

         330 101 126 305

         143 126 210 300 }.map { |x| sprintf( "%02X", x.oct [...]

Heckle: Nifty Ruby Code Mutation Tester

I love the idea behind Heckle:

Heckle is a mutation tester. It modifies your code and runs your tests to make sure they fail. The idea is that if code can be changed and your tests don't notice, either that code isn't being covered or it doesn't do anything.

To install:

sudo gem install heckle

Maybe I'll spend today [...]

Rails: Bar Graph Helper 0.1 Released

As promised yesterday, I've rewritten the CSS Graphs Helper to provide much more functionality and flexibility. It is also not as a plugin, nor as a class, but as a Rails helper module. You can skip straight to the "manual" here: Rails: Bar Graph Helper or go right to the source code here: Rails: Bar [...]

Rails Gems Pr0n

In the spirit of Robby and Chad et al. posting their Rails gems in response to Mike's question:

Which RubyGems are you sporting?

actionmailer (1.3.2, 1.3.1, 1.2.5)
actionpack (1.13.2, 1.13.1, 1.12.5)
actionwebservice (1.2.2, 1.2.1, 1.1.6)
activerecord (1.15.2, 1.15.1, 1.14.4)
activesupport (1.4.1, 1.4.0, 1.3.1)
fcgi (0.8.7)
ferret (0.10.14)
hoe (1.1.7)
mysql (2.7)
rails (1.2.2, 1.2.1, 1.1.6)
railsbench (0.9.1)
rake (0.7.1)
rmagick (1.15.2)
rubyforge (0.4.0)
sources (0.0.1)

Which just goes to show that I [...]

Rails: CSS Graph and “wrong number of arguments”

There's a great plugin for Rails called CSS Graphs Helper that does, well, just that: graphs things. However the instructions on that page say to implement a graph like so:
PLAIN TEXT
RUBY:

<%= bar_graph  ['Gouda', 24], ['Havarti', 9], ['Provolone', 81], ['GjeitÃst', 57], ['Stilton', 42] %>

This threw a "wrong number of arguments (5 for 1)" error when [...]

Ruby: No Such File to Load: net/https

.../custom_require.rb:27:in `gem_original_require': no such file to load -- net/https (MissingSourceFile)

If you get this error when getting your Rails app up and running under Ubuntu (Dapper in my case) it means you still need to install the libopenssl-ruby library:

apt-get install libopenssl-ruby

I recommend installling that before you install Rails.

Rails: Extending Classes, Creating Mixins

I tend towards disliking the use of inheritance with my own objects. It's great for components in frameworks where I only have to worry about the end product but in my own code I default towards thinking of inheritance as a flaw and only concede when no other alternative is as elegant.
Which is why I'm [...]

Rails: A Question About Constants

This is one of those questions for which the elegant answer feels like it ought to be simple. In my app I have a module called Constants which contains application-specific constants (such as a copyright notice, for instance).
Putting the constants.rb file into app/helpers and then referencing the constant ala <%= Constants::COPYRIGHT_MESSAGE %> works well [...]

Ruby: Comparing an Object’s Class in a Case Statement

Here's a little tidbit that I had to dig long and hard on Google to find. If you want to use a case statement in Ruby to act on the class of an object, the following - my initial attempt that I thought ought to work - won't work:
PLAIN TEXT
RUBY:

def get_value( pResult )

    case [...]

Rails: Serving a Site With Apache Under OS X

Almost all the Rails documentation assumes that you'll be serving your app up using either WEBrick or lighttpd, neither of which are suitable for me since I use Apache for both development and on the live servers.
Unfortunatelly finding Apache info can be difficult so to that end, here's what I've done to get my Rails [...]

keep looking »