So I don't have a model called Person, but I use hashes like {:name => "Siddharth", :sex => "Y"}. Great. Now I want to validate the presence of certain fields before persisting to the database. What do I do?
Module PersonValidation
function validate_presence_of_name(person_hash)
person_hash[:errors][:name] = "EEENKKK!" unless person_hash[:name]
end
...
...
end
So I must be missing something because how is this different from a class in a dynamic language? The above approach means you can easily swap out functions in one module for another and thus not tie the validation implementation to the structure of the loan hash, but this is trivially simple in Ruby even using classes. Is there some other benefit?
BG has already given an excellent answer. Personally I don't like OOP much for the same reason I don't like [much] languages with mutable data structures. As Alan Kay famously said: ``When you have a 'setter' on an object, you have turned an object back into a data structure'' [Copy-pasted from the web] [Watch this presentation: http://tele-task.de/archive/video/flash/14029/] . Personally I'll be much happier programming in a language with a good namespace design and immutable data structures. Such a language is much simpler and better to reason about. Clojure is one such language and I absolutely love it because of that. If I ever need a usecase for multiple dispatch I can use multimethods. That said OOP as per Alan Kay is more about message passing than anything else.