[#3006] mismatched quotation — "stevan apter" <apter@...>

ruby documentation uses a punctuation convention i've never seen

13 messages 2000/05/27

[ruby-talk:02614] Re: Structs and dictionary keys

From: matz@... (Yukihiro Matsumoto)
Date: 2000-05-02 09:43:19 UTC
List: ruby-talk #2614
Hi,

In message "[ruby-talk:02613] Structs and dictionary keys"
    on 00/05/02, Wes Nakamura <wknaka@pobox.com> writes:

|What's the purpose of the name when you create a new Struct?
|
|>From the docs:
|
|dog = Struct.new("Dog", :name, :age)
|
|Can you reference something via the name "Dog"?

It will be the name of the newly created subclass of Struct.
You can access it like Struct::Dog.  If you want to leave struct
unnamed, just remove first string argument (for 1.5.x) . e.g.

  dog = Struct.new(:name, :age)

|Also, are frozen arrays suitable for dictionary keys?
|
|Will the second [1,2] always dereference properly?
|
| { [1,2].freeze => "test" }[[1,2]]

Yes.

|I know that if you don't freeze the key and then change it, apparently
|you can't access the value via the key at all anymore. 

Use 'rehash' method of Hash class to make them accessible again.

							matz.

In This Thread

Prev Next