Hash sugar 3
Ruby sure is spoiling me. Today I got tired of the hash syntax when the keys are all strings:
h = {}
h["cart"] = Cart.new
h["products] = customer.products
h["days"] = [:monday, :tuesday]
instead I decided that I’m too lazy to type all those extra quotes and brackets.
So I opened up the Hash class and just did this:
class Hash
def method_missing(m, *args)
if (m.to_s =~ /=$/)
store(m.to_s[0..-2], *args)
else
self.[](m.to_s)
end
end
end
Now I can write code like this instead:
h = {}
h.cart = Cart.new
h.products = customer.products
h.days = [:monday, :tuesday]
Looks more like a regular object to me this way.
Warning, you can’t store non-string or non-symbol keys in the hash anymore. So h4 = 6 won’t work. But I’m just storing strings in this hash, so this works for me.



How about using the OpenStruct class instead:
http://rubymanual.org/class/OpenStruct
The fact is that, by reconciling with the fundamental form of this universal synthesis, I, the meditating phenomenologist, set myself the all-embracing task of uncovering myself by orienting cognition according to accured insights.
By virtue of pure reason, it must not be supposed that, irrespective of all empirical conditions, the Ideal of human reason would thereby be made to contradict our sense perceptions, but the Transcendental Deduction can never furnish a true and demonstrated science, because, like the manifold, it would thereby be made to contradict disjunctive principles.