Functional Programming With Ruby
code.google.com
code.google.com
For example, you can have referential transparency in your methods, which will allow for easier debugging. You can also strive for simpler data structures and even freeze objects to make them immutable[2].
[1] http://www.johndcook.com/blog/2009/03/23/functional-in-the-s... [2] http://ontwik.com/ruby/better-ruby-through-functional-progra...
input.inject({}) do |hash, item|
hash.merge(item => process(item))
end
Far, far slower, more memory intensive (big deal, given ruby's gc), and uglyer than the sane (and commonly accepted) Hash[input.map do |item|
[item, process(item)]
end]