forked from runpaint/read-ruby
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref/Struct: Write reference page for Struct.
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<appendix version="5.0" | ||
xml:id="ref.struct" xml:lang="en" xmlns="http://docbook.org/ns/docbook" | ||
xmlns:xi="http://www.w3.org/2001/XInclude" | ||
xmlns:xlink="http://www.w3.org/1999/xlink"> | ||
|
||
<title>Struct</title> | ||
|
||
<para><methodsynopsis><type>Struct::Example</type><methodname>Struct.new</methodname><methodparam choice="opt"><parameter>name</parameter></methodparam><methodparam choice="opt" rep="repeat"><parameter>member</parameter></methodparam><methodparam choice="opt"><parameter>{ }</parameter></methodparam></methodsynopsis> Initialises and returns a new <literal>Class</literal> inheriting from <literal>Struct</literal>. It is named <literal>Struct::<replaceable>name</replaceable></literal>, or is anonymous if <parameter>name</parameter> is omitted. An accessor method is defined for each <parameter>member</parameter> <literal>Symbol</literal>. If a block is given, it is evaluated in the context of the new <literal>Struct</literal>’s class. In the descriptions that follow, <literal>Struct::Example</literal> is a <literal>Class</literal> returned by this method.</para> | ||
|
||
<para><methodsynopsis><type>Struct::Example</type><methodname>Struct::Example.new</methodname><methodparam rep="repeat"><parameter>value</parameter></methodparam></methodsynopsis> Instantiates and returns an instance of the receiver. Each <parameter>value</parameter> is assigned to the corresponding member; an omitted <parameter>value</parameter> is <literal>nil</literal>. An <exceptionname>ArgumentError</exceptionname> is raised if more <parameter>value</parameter>s are given than there are members. Aliased by <function>Struct::Example[]</function>.</para> | ||
|
||
<para><methodsynopsis><type>Struct::Example</type><methodname>Struct::Example[]</methodname><methodparam rep="repeat"><parameter>value</parameter></methodparam></methodsynopsis> Aliases <function>Struct::Example.new</function>.</para> | ||
|
||
<para><methodsynopsis><type>Array</type><methodname>Struct::Example.members</methodname><void/></methodsynopsis> Returns the names of the receiver’s members as an <literal>Array</literal> of <literal>Symbol</literal>s.</para> | ||
|
||
<para><methodsynopsis><type>true or false</type><methodname>Struct::Example#==</methodname><methodparam><parameter>object</parameter></methodparam></methodsynopsis> Returns <literal>true</literal> if <parameter>object</parameter> was generated by <function>Struct.new</function> and has the same number of members as the receiver, each of which have the same names and equal values according to <function>#==</function>; otherwise, <literal>false</literal>.</para> | ||
|
||
<para><methodsynopsis><type>Object</type><methodname>Struct::Example#[]</methodname><methodparam><parameter>position</parameter></methodparam></methodsynopsis> | ||
<methodsynopsis><type>Object</type><methodname>Struct::Example#[]</methodname><methodparam><parameter>name</parameter></methodparam></methodsynopsis> Returns the value of the given member, identified either by its <literal>Fixnum</literal> <parameter>position</parameter> or <literal>Symbol</literal> <parameter>name</parameter>. If there isn’t such a member, the first form raises an <exceptionname>IndexError</exceptionname>, and the second form raises a <exceptionname>NameError</exceptionname>.</para> | ||
|
||
<para><methodsynopsis><type>Object</type><methodname>Struct::Example#[]=</methodname><methodparam><parameter>position</parameter></methodparam><methodparam><parameter>object</parameter></methodparam></methodsynopsis> | ||
<methodsynopsis><type>Object</type><methodname>Struct::Example#[]=</methodname><methodparam><parameter>name</parameter></methodparam><methodparam><parameter>object</parameter></methodparam></methodsynopsis> Sets the value of the given member to <parameter>object</parameter>. A member is identified either by its <literal>Fixnum</literal> <parameter>position</parameter> or <literal>Symbol</literal> <parameter>name</parameter>. If there isn’t such a member, the first form raises an <exceptionname>IndexError</exceptionname>, and the second form raises a <exceptionname>NameError</exceptionname>.</para> | ||
|
||
<para><methodsynopsis><type>Struct::Example or Enumerator</type><methodname>Struct::Example#each</methodname><methodparam><parameter>{|value| }</parameter></methodparam></methodsynopsis> Yields the value of each member in turn, returning the receiver. If the block is omitted, an <literal>Enumerator</literal> is returned.</para> | ||
|
||
<para><methodsynopsis><type>Struct::Example or Enumerator</type><methodname>Struct::Example#each_pair</methodname><methodparam><parameter>{|member, value| }</parameter></methodparam></methodsynopsis> Yields the name of each <literal>Symbol</literal> member, in turn, along with its value, returning the receiver. If the block is omitted, an <literal>Enumerator</literal> is returned.</para> | ||
|
||
<para><methodsynopsis><type>Integer</type><methodname>Struct::Example#length</methodname><void/></methodsynopsis> Returns the number of members in the receiver. Aliased by <function>Struct::Example#size</function>.</para> | ||
|
||
<para><methodsynopsis><type>Array</type><methodname>Struct::Example#members</methodname><void/></methodsynopsis> Returns the names of the receiver’s members as an <literal>Array</literal> of <literal>Symbol</literal>s.</para> | ||
|
||
<para><methodsynopsis><type>Integer</type><methodname>Struct::Example#size</methodname><void/></methodsynopsis> Aliases <function>Struct::Example#length</function>.</para> | ||
|
||
<para><methodsynopsis><type>Array</type><methodname>Struct::Example#to_a</methodname><void/></methodsynopsis> Returns the values of the receiver’s members. Aliased by <function>Struct::Example#values</function>.</para> | ||
|
||
<para><methodsynopsis><type>Array</type><methodname>Struct::Example#values</methodname><void/></methodsynopsis> Aliases <function>Struct::Example#to_a</function>.</para> | ||
|
||
<para><methodsynopsis><type>Array</type><methodname>Struct::Example#values_at</methodname><methodparam rep="repeat"><parameter>position</parameter></methodparam></methodsynopsis> Returns the values corresponding to the given members, which are specified as <literal>Fixnum</literal> <parameter>position</parameter>s or <literal>Range</literal>s of the same.</para> | ||
</appendix> |