D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Struct
/
Filename :
cdesc-Struct.ri
back
Copy
U:RDoc::NormalClass[iI"Struct:ET@I"Object;To:RDoc::Markup::Document:@parts[o;;[ : @fileI"$ext/json/lib/json/add/struct.rb;T:0@omit_headings_from_table_of_contents_below0o;;[7o:RDoc::Markup::Paragraph;[I"G\Class \Struct provides a convenient way to create a simple class ;TI"%that can store and fetch values.;To:RDoc::Markup::BlankLine o;;[I"MThis example creates a subclass of +Struct+, <tt>Struct::Customer</tt>; ;TI"@the first argument, a string, is the name of the subclass; ;TI"Othe other arguments, symbols, determine the _members_ of the new subclass.;T@o:RDoc::Markup::Verbatim;[ I">Customer = Struct.new('Customer', :name, :address, :zip) ;TI"1Customer.name # => "Struct::Customer" ;TI"$Customer.class # => Class ;TI"%Customer.superclass # => Struct ;T:@format0o;;[I"JCorresponding to each member are two methods, a writer and a reader, ;TI"!that store and fetch values:;T@o; ;[I"/methods = Customer.instance_methods false ;TI"Dmethods # => [:zip, :address=, :zip=, :address, :name, :name=] ;T;0o;;[I"1An instance of the subclass may be created, ;TI"@and its members assigned values, via method <tt>::new</tt>:;T@o; ;[I"Ejoe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) ;TI"fjoe # => #<struct Struct::Customer name="Joe Smith", address="123 Maple, Anytown NC", zip=12345> ;T;0o;;[I"+The member values may be managed thus:;T@o; ;[I""joe.name # => "Joe Smith" ;TI"joe.name = 'Joseph Smith' ;TI"%joe.name # => "Joseph Smith" ;T;0o;;[I"UAnd thus; note that member name may be expressed as either a string or a symbol:;T@o; ;[I"%joe[:name] # => "Joseph Smith" ;TI"&joe[:name] = 'Joseph Smith, Jr.' ;TI"*joe['name'] # => "Joseph Smith, Jr." ;T;0o;;[I"See Struct::new.;T@S:RDoc::Markup::Heading: leveli: textI"What's Here;T@o;;[I"-First, what's elsewhere. \Class \Struct:;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0;[o;;[I"AInherits from {class Object}[rdoc-ref:Object@What-27s+Here].;To;;0;[o;;[I"FIncludes {module Enumerable}[rdoc-ref:Enumerable@What-27s+Here], ;TI"1which provides dozens of additional methods.;T@o;;[I"]See also Data, which is a somewhat similar, but stricter concept for defining immutable ;TI"value objects.;T@o;;[I">Here, class \Struct provides methods that are useful for:;T@o;;;;[o;;0;[o;;[I"Y{Creating a Struct Subclass}[rdoc-ref:Struct@Methods+for+Creating+a+Struct+Subclass];To;;0;[o;;[I"5{Querying}[rdoc-ref:Struct@Methods+for+Querying];To;;0;[o;;[I"7{Comparing}[rdoc-ref:Struct@Methods+for+Comparing];To;;0;[o;;[I"5{Fetching}[rdoc-ref:Struct@Methods+for+Fetching];To;;0;[o;;[I"7{Assigning}[rdoc-ref:Struct@Methods+for+Assigning];To;;0;[o;;[I"7{Iterating}[rdoc-ref:Struct@Methods+for+Iterating];To;;0;[o;;[I"9{Converting}[rdoc-ref:Struct@Methods+for+Converting];T@S;;i;I"+Methods for Creating a Struct Subclass;T@o;;;;[o;;0;[o;;[I".::new: Returns a new subclass of \Struct.;T@S;;i;I"Methods for Querying;T@o;;;;[o;;0;[o;;[I"*#hash: Returns the integer hash code.;To;;0;[o;;[I"?#size (aliased as #length): Returns the number of members.;T@S;;i;I"Methods for Comparing;T@o;;;;[o;;0;[o;;[I"O#==: Returns whether a given object is equal to +self+, using <tt>==</tt> ;TI"to compare member values.;To;;0;[o;;[I"?#eql?: Returns whether a given object is equal to +self+, ;TI"2using <tt>eql?</tt> to compare member values.;T@S;;i;I"Methods for Fetching;T@o;;;;[o;;0;[o;;[I"@#[]: Returns the value associated with a given member name.;To;;0;[o;;[I"_#to_a (aliased as #values, #deconstruct): Returns the member values in +self+ as an array.;To;;0;[o;;[I"?#deconstruct_keys: Returns a hash of the name/value pairs ;TI"for given member names.;To;;0;[o;;[I"B#dig: Returns the object in nested objects that is specified ;TI"5by a given member name and additional arguments.;To;;0;[o;;[I"4#members: Returns an array of the member names.;To;;0;[o;;[I"R#select (aliased as #filter): Returns an array of member values from +self+, ;TI"$as selected by the given block.;To;;0;[o;;[I"K#values_at: Returns an array containing values for given member names.;T@S;;i;I"Methods for Assigning;T@o;;;;[o;;0;[o;;[I"8#[]=: Assigns a given value to a given member name.;T@S;;i;I"Methods for Iterating;T@o;;;;[o;;0;[o;;[I"6#each: Calls a given block with each member name.;To;;0;[o;;[I"F#each_pair: Calls a given block with each member name/value pair.;T@S;;i;I"Methods for Converting;T@o;;;;[o;;0;[o;;[I"L#inspect (aliased as #to_s): Returns a string representation of +self+.;To;;0;[o;;[I"D#to_h: Returns a hash of the member name/value pairs in +self+.;T; I" struct.c;T; 0; 0; 0[ [ [[I"Enumerable;To;;[ ; @�; 0I" struct.c;T[[I" class;T[[:public[ [I"json_create;TI"$ext/json/lib/json/add/struct.rb;T[I"keyword_init?;T@�[I"members;T@�[I"new;T@�[:protected[ [:private[ [I" instance;T[[;[[I"==;T@�[I"[];T@�[I"[]=;T@�[I"as_json;T@[I"deconstruct;T@�[I"deconstruct_keys;T@�[I"dig;T@�[I" each;T@�[I"each_pair;T@�[I" eql?;T@�[I"filter;T@�[I" hash;T@�[I"inspect;T@�[I"length;T@�[I"members;T@�[I"select;T@�[I" size;T@�[I" to_a;T@�[I" to_h;T@�[I"to_json;T@[I" to_s;T@�[I"values;T@�[I"values_at;T@�[;[ [;[ [ [U:RDoc::Context::Section[i 0o;;[ ; 0; 0[@ I"lib/pp.rb;T@�@�cRDoc::TopLevel