ri is a commend line program that may or may not have been installed
with your distribution of ruby. It’s a viewer for the documentation
that was (hopefully) also installed with your disctribution of ruby.
If you type “ri Hash.new” it will display information on the class
method Hash.new. If you were to use the form “ri Hash#keys” then you
weould be requesting information about the instance method keys that may
be called on a hash object.
Try it, and if you don’t have it installed then someone can help you get
it set up.
I believe that’s the first empty || I’ve ever seen. It’s awfully
confusing (my first reaction was: what or an empty array? I’d
strongly encourage you to eschew that construct. It’s deservedly
unheard of
===============================================================================
| ara [dot] t [dot] howard [at] gmail [dot] com
| all happiness comes from the desire for others to be happy. all misery
| comes from the desire for oneself to be happy.
| – bodhicaryavatara
I believe that’s the first empty || I’ve ever seen. It’s awfully
confusing (my first reaction was: what or an empty array? I’d
strongly encourage you to eschew that construct. It’s deservedly
unheard of
i must confess i love it! probably won’t use it much. but i love it.
I love it too, and will use it simply because David said he’d never seen
it before.
I believe that’s the first empty || I’ve ever seen. It’s awfully
confusing (my first reaction was: what or an empty array? I’d
strongly encourage you to eschew that construct. It’s deservedly
unheard of
i must confess i love it! probably won’t use it much. but i love it.
Keep it firmly in mind if there’s every another obfuscated Ruby
contest…
I believe that’s the first empty || I’ve ever seen. It’s awfully
confusing (my first reaction was: what or an empty array? I’d
strongly encourage you to eschew that construct. It’s deservedly
unheard of
i must confess i love it! probably won’t use it much. but i love it.
ROFL. Yes indeed. I have yet to really reveal it, but I have quite a
penchant for obfuscated Ruby code, and plan to compete in the next
IORCC. I also enjoy Ruby Golf, as can be seen in my recent Ruby Q.
submission.
I just like the irony that it takes a really good Ruby programmer to
write such bad, evil code
I believe that’s the first empty || I’ve ever seen. It’s awfully
confusing (my first reaction was: what or an empty array? I’d
strongly encourage you to eschew that construct. It’s deservedly
unheard of
i must confess i love it! probably won’t use it much. but i love it.
I believe that’s the first empty || I’ve ever seen. It’s awfully
confusing (my first reaction was: what or an empty array? I’d
strongly encourage you to eschew that construct. It’s deservedly
unheard of
Perhaps I’m missing something. Is there something wrong with the
following?
Perhaps I’m missing something. Is there something wrong with the following?
a = Hash.new { [] }
irb tells me that it gets a new array each time.
No that is how it works and that is basically what Jeff’s code does.
He just has empty “goal-posts” in the block as well (it isn’t really
an or operation.) He gets around the new array every time thing by
using self[key] <<= value, which is self[key] = self[key] << value.
The block will only be called when there is no values for the given
key, and once the above code is called, there will be a value for the
given key (the array.) It is pretty slick (I didn’t even know <<=
existed.)