I am spoiled June 20, 2007 05:06 over 4 years ago
Ruby sure is spoiling me. Today I tock the hash syntax and played a little with the keys and values.
h = {}
h["cart"] = Cart.new
h["products] = products
h["days"] = [:monday, :tuesday]
instead I decided that I’m too lazy to type all those extra quotes and brackets.
Hmm, ruby is a open language so I just opened up the Hash class and 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 = products
h.days = [:monday, :tuesday]
Pretty amazing way to chance the core syntactic language!
By Frank Vilhelmsen - 1 tag: ruby - 1 comment on I am spoiled - Add comment
Olle Jonsson June 20, 2007 05:06 over 4 years ago
If you dig extending core stuff, take a deep breath and get the Facets gem.
http://facets.rubyforge.org/
“Ruby Facets is the single largest collection of core extension methods and standard library additions available for the Ruby programming language.”
Often you find details in this (can-of-wormsy) large core extension gem.