From: Michael Trier Date: 2006-05-15T09:39:44+09:00 Subject: Mapping a String to Properties - A Better Way? I have a piece of code that works fine, but I'm wondering if there is a better way to go about it. The method is receiving a hash (params) and in that hash are a group of items named item_1, item_2, item_3, and so on. Each of these items contains a whitespace separated list of values. For instance: item_1 => "120 355 240 145" item_2 => "130 400 100 100" These values map to x, y, width, and height properties on an object. Here's my code, but is there a better, more Ruby way to do this: params.each do |key, value| if key =~ /^item_/ a = value.split Item.update(key.split("_")[1], :x => a[0], :y => a[1], :width => a[2], :height => a[3]) end end Thanks in advance for any pointers. Michael