Heaven on Rails?
I'm very positively surprised with Ruby on Rails.
Every time I believe it can't astonish me any further, it does again. Check this excerpt from AWDWR (Agile Web Development with Rails):
def self.authenticate(name, password)
user = self.find_by_name(name)
if user
expected_password = encrypted_password(password, user.salt)
if user.hashed_password != expected_password
user = nil
end
end
user
end
This code uses a clever little Active Record trick. You see that the first line of the method calls find_by_name. But we don’t define a method with that name.
However, Active Record notices the call to an undefined method and spots that it starts with the string find_by and ends with the name of a column. It then dynamically constructs a finder method for us, adding it to our class.
That's completely INSANE, and at the same time what I'd expect from a clever, modern programming language. Ruby on Rails(RoR) lives to my expectations like none of the programming languages I've used before did. I'm very well impressed, and I'll be posting more about my impressions along the way. This is just one of many clever stuff baked in RoR. BTW if you'd like to learn RoR, buy that book! It's a great comprehensive and entertaining book. You can find it in Pragmatic Programmers.
#121