Skip to content

Commit

Permalink
Ref/Struct: Write reference page for Struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
runpaint committed Jan 28, 2011
1 parent 677a27b commit d2edaab
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions book.xml
Expand Up @@ -89,6 +89,7 @@
<xi:include href="src/ref/regexp.xml"/>
<xi:include href="src/ref/signal.xml"/>
<xi:include href="src/ref/string.xml"/>
<xi:include href="src/ref/struct.xml"/>
</part>

<xi:include href="src/bibliography.xml"/>
Expand Down
40 changes: 40 additions & 0 deletions src/ref/struct.xml
@@ -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>

0 comments on commit d2edaab

Please sign in to comment.