ÿØÿà JFIF ÿÛ „ ( %!1!%*+...983,7(-.-
U:RDoc::AnyMethod[iI"new:ETI"Struct::new;TT:privateo:RDoc::Markup::Document:@parts[-o:RDoc::Markup::Paragraph; [I"OStruct.new returns a new subclass of +Struct+. The new subclass:;To:RDoc::Markup::BlankLine o:RDoc::Markup::List:
@type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o;
; [I"BMay be anonymous, or may have the name given by +class_name+.;To;;0; [o;
; [I"1May have members as given by +member_names+.;To;;0; [o;
; [I"BMay have initialization via ordinary arguments (the default) ;TI"Hor via keyword arguments (if keyword_init: true is given).;T@o;
; [I">The new subclass has its own method ::new; thus:;T@o:RDoc::Markup::Verbatim; [I":Foo = Struct.new('Foo', :foo, :bar) # => Struct::Foo
;TI"Qf = Foo.new(0, 1) # => #
;T:@format0o;
; [I"\Class Name;T@o;
; [I"(With string argument +class_name+, ;TI"Sreturns a new subclass of +Struct+ named Struct::class_name:;T@o;; [I":Foo = Struct.new('Foo', :foo, :bar) # => Struct::Foo
;TI" "Struct::Foo"
;TI"5Foo.superclass # => Struct
;T;0o;
; [I"+Without string argument +class_name+, ;TI"2returns a new anonymous subclass of +Struct+:;T@o;; [I"*Struct.new(:foo, :bar).name # => nil
;T;0o;
; [I"Block;T@o;
; [I"FWith a block given, the created subclass is yielded to the block:;T@o;; [I"GCustomer = Struct.new('Customer', :name, :address) do |new_class|
;TI", p "The new subclass is #{new_class}"
;TI" def greeting
;TI"' "Hello #{name} at #{address}"
;TI" end
;TI")end # => Struct::Customer
;TI"-dave = Customer.new('Dave', '123 Main')
;TI"Ndave # => #
;TI"1dave.greeting # => "Hello Dave at 123 Main"
;T;0o;
; [I"&Output, from Struct.new:;T@o;; [I","The new subclass is Struct::Customer"
;T;0o;
; [I"Member Names;T@o;
; [I"&\Symbol arguments +member_names+ ;TI"0determines the members of the new subclass:;T@o;; [I"=Struct.new(:foo, :bar).members # => [:foo, :bar]
;TI"=Struct.new('Foo', :foo, :bar).members # => [:foo, :bar]
;T;0o;
; [I"KThe new subclass has instance methods corresponding to +member_names+:;T@o;; [
I")Foo = Struct.new('Foo', :foo, :bar)
;TI"AFoo.instance_methods(false) # => [:foo, :bar, :foo=, :bar=]
;TI"Mf = Foo.new # => #
;TI"*f.foo # => nil
;TI"(f.foo = 0 # => 0
;TI"*f.bar # => nil
;TI"(f.bar = 1 # => 1
;TI"If # => #
;T;0o;
; [I"Singleton Methods;T@o;
; [I"CA subclass returned by Struct.new has these singleton methods:;T@o;;
;;[o;;0; [
o;
; [I"A\Method ::new creates an instance of the subclass:;T@o;; [ I"BFoo.new # => #
;TI"@Foo.new(0) # => #
;TI">Foo.new(0, 1) # => #
;TI"BFoo.new(0, 1, 2) # Raises ArgumentError: struct size differs
;T;0o;
; [I"A\Method ::[] is an alias for method ::new.;T@o;;0; [o;
; [I"O\Method :inspect returns a string representation of the subclass:;T@o;; [I"Foo.inspect
;TI"# => "Struct::Foo"
;T;0o;;0; [o;
; [I"E\Method ::members returns an array of the member names:;T@o;; [I"#Foo.members # => [:foo, :bar]
;T;0o;
; [I"Keyword Argument;T@o;
; [ I"PBy default, the arguments for initializing an instance of the new subclass ;TI"5are ordinary arguments (not keyword arguments). ;TI"AWith optional keyword argument keyword_init: true, ;TI" Struct::Foo
;TI"EFoo.new(0, 1) # => #
;TI" # With keyword_init: true.
;TI"6Bar = Struct.new(:foo, :bar, keyword_init: true)
;TI":Bar # => # => Bar(keyword_init: true)
;TI" #;T;0:
@fileI"
struct.c;T:0@omit_headings_from_table_of_contents_below0I"?Struct.new(*member_names, keyword_init: false){|Struct_subclass| ... } -> Struct_subclass
Struct.new(class_name, *member_names, keyword_init: false){|Struct_subclass| ... } -> Struct_subclass
Struct_subclass.new(*member_names) -> Struct_subclass_instance
Struct_subclass.new(**member_names) -> Struct_subclass_instance
;T0[ I"(*args);T@ŸFI"Struct;TcRDoc::NormalClass00