How about param_name instead of params[:name]

Neat trick, but I think it’s harder to read. My editor easily identifies hashes / symbols, etc.
I’d prefer something like

params.id
params.name

or

params.user.id
params.user.first_name

instead of

params[:user][:first_name]

:slight_smile:

What you're asking for is really quite simple and shouldn't slow you
down. However, it'll get confused when you have a word set as a key as
both a string and a symbol, but you should avoid that anyways.

http://pastie.caboo.se/123603

Good luck!

Well, no… that’s why you’re using method_missing. to_s is defined, so method_missing doesn’t get fired.

But I do think it’s really more of a waste of time :slight_smile:

You guys are very right, and this is more for just-so-you-know than
actuall use in a production environment, but you could use it if your
hash doesnt have a lot of keys. How many of you have had a hash with a
key of to_a? Alternatively, you could do something else, which I'll
have up in a few.

It’s a fun excercise but I don’t think what’s there is really that hard to read or use. I’m just interested in this for the academic side of things. It’s neat to see what Ruby can do.

It's really simple to add extra "characters" to make sure there's no
overlapping. For example, "hash.key.user.id" could be done quite
easily, adapting from my code earlier. I'll have that up in a moment.

It's really simple to add extra "characters" to make sure there's no
overlapping. For example, "hash.key.user.id" could be done quite
easily, adapting from my code earlier. I'll have that up in a moment.

Here: http://pastie.caboo.se/123991

The method "key" just returns the hash, then the code from before
kicks in. You can change key to whatever you want to make it better
for you.