On Wed, Mar 31, 2010 at 4:58 PM, Max Schmidt
<max.schmidt.privat / googlemail.com> wrote:
>>> 3 -
>>>>Why don't you allow one letter words?
>>> Because strings with one letter aren't any words, they are characters.
>>> My aim was to develop a dictionary where you can organize "real-life"
>>> words
>>
>> "a" is a word :-)
> This is a good argument, I was obviously too focused on my native
> language :)

Sorry about that ! You know your requirements :-)

>>> Do you mean to avoid exceptions when the words are frozen? If yes, I
>>> would throw an Exception if either of the two words is frozen.
>>
>> No, what I mean is that the client can modify the String object after
>> inserting it in the dictionary:
> You surely mean the DictionaryEntry
>
>> @word1 = word1.dup unless word1.frozen?
>> @word2 = word2.dup unless word2.frozen?
>>
>> The frozen check is just an optimization, because if the string is
>> frozen it's not going to be modified by the client, and so you are
>> safe just using it.
>>
> If you assume that word1 is frozen, then @word1 would be assigned to
> nil, wouldn't it? Or is the unless refering to the - and exclusively -
> to the ".dup"?

No, I screwed up and you are right. I'd do it something like:

@word1 = word1.frozen? ? word1 : word1.dup


>> If it's just for
>> convenience, I think you should drop it, because it's giving those
>> objects a behaviour that they shouldn't have.
>
> Do you mean that the boolean equality operator (==) normally exclusively
> compares with the class it is defined by?

I think generally yes. I'm not sure if it's a hard rule, though, and
in some cases it might make sense. If you do that, I would certainly
include Enumerable in your class, so that then both are Enumerable, so
you might argue that the comparison really makes sense :-)


> Last question:
> I posted this code on an other ruby forum and was criticized about my
> coding style: Indents are always done with two whitespaces rather than
> with tabs like I have. Have you heard anything about such a "unwritten
> rule"?

Yeah, the typical convention is to use two spaces instead of tabs. But
criticized? Come on, it's a convention and you said you were new to
Ruby...
The reason I dislike tabs most is that I cannot copy and paste code
with tabs into irb, cause it shows me the current directory listing,
like a completion in the shell.

So, in my opinion, if you want to share code with the Ruby community,
I think you should try to adapt to the general conventions, it makes
it easier for everybody.

Jesus.