From: "Jesús Gabriel y Galán" Date: 2013-04-11T18:05:09+09:00 Subject: Re: confusion with Struct class On Thu, Apr 11, 2013 at 10:45 AM, Love U Ruby wrote: > I went to there - http://www.ruby-doc.org/core-2.0/Struct.html but the > below mentioned not cleared. > > Customer = Struct.new(:name, :address) > p Customer.class #=>class > > Struct.new("Customer", :name, :address) > p Customer.class #`
': uninitialized constant Customer (NameError) > > Can anyone help me what's the difference between these two construct? > If you read the doc you referenced closely: "Creates a new class, named by aString, containing accessor methods for the given symbols. If the name aString is omitted, an anonymous structure class will be created. Otherwise, ***the name of this struct will appear as a constant in class Struct***, so it must be unique for all Structs in the system and should start with a capital letter. Assigning a structure class to a constant effectively gives the class the name of the constant." Check the part between *** 1.9.2p290 :001 > Struct.new("Customer", :name, :address) => Struct::Customer 1.9.2p290 :002 > p Struct::Customer Struct::Customer => Struct::Customer 1.9.2p290 :003 > p Struct::Customer.class Class => Class Jesus.