About
fv_2007
Agile innovative developer with deep insight into lots of platforms, technologies and protocols. Absolute “early adopter” in Web 2.0 technologies and more. Large professional network and eagerly talking about architecture, strategy, design patterns, restful ressources, object-oriented thinking and modeling languages such as PML. Special interest in programminglanguages constructs, knowledge on languages like Smalltalk, Erlang, Java, Clojure, Scala, Ruby... read more
Language

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.