A Couple of Notes Concerning my First Outings with Ruby
So I've finally dove into something slightly more complicated than "Hello, World!" style scripts (← how's that for some long text linkage).
First notes, when I program in a language that doesn't have sigils in front of the variables, my brain gets confused and thinks it is programming Javascript. I get a Pavlovian response of pain as I shudder at the thought of having to write document.getElementByID 500 times. I had this same brain-switching problem when I was constantly going back and forth with PHP and Perl. I drop from PHP to Perl and start writing lines and lines of code with $ symbols in front of arrays and hashes. Perl would obviously become very unhappy. It was even worse when I would write Perl code in the .php files.
That one section of code:
user.attributes.sort_by{ |attr| attr }.each{ |attr|
user.send(attr.to_sym).each{ |value| puts "#{attr}: #{value}" }
}
If I wasn't originally a Perl programmer, that probably would have looked more like:
user.attributes.sort_by{ |attr| attr }.each do |attr|
values = user.send(attr.to_sym)
values.each do |value|
puts "#{attr}: #{value}"
end
end
And I don't know if this just means I've been programming with Perl too long, but Ruby certainly feels strangely familiar. Perl++ of a kind.
Post a comment