<!DOCTYPE html> <html> <head> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <title>module LazyStruct::Mixin - RDoc Documentation</title> <link type="text/css" media="screen" href="../rdoc.css" rel="stylesheet"> <script type="text/javascript"> var rdoc_rel_prefix = "../"; </script> <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script> <script type="text/javascript" charset="utf-8" src="../js/navigation.js"></script> <script type="text/javascript" charset="utf-8" src="../js/search_index.js"></script> <script type="text/javascript" charset="utf-8" src="../js/search.js"></script> <script type="text/javascript" charset="utf-8" src="../js/searcher.js"></script> <script type="text/javascript" charset="utf-8" src="../js/darkfish.js"></script> <body id="top" class="module"> <nav id="metadata"> <nav id="home-section" class="section"> <h3 class="section-header"> <a href="../index.html">Home</a> <a href="../table_of_contents.html#classes">Classes</a> <a href="../table_of_contents.html#methods">Methods</a> </h3> </nav> <nav id="search-section" class="section project-section" class="initially-hidden"> <form action="#" method="get" accept-charset="utf-8"> <h3 class="section-header"> <input type="text" name="search" placeholder="Search" id="search-field" title="Type to search, Up and Down to navigate, Enter to load"> </h3> </form> <ul id="search-results" class="initially-hidden"></ul> </nav> <div id="file-metadata"> <nav id="file-list-section" class="section"> <h3 class="section-header">Defined In</h3> <ul> <li>install.rb </ul> </nav> </div> <div id="class-metadata"> <!-- Method Quickref --> <nav id="method-list-section" class="section"> <h3 class="section-header">Methods</h3> <ul class="link-list"> <li><a href="#method-i-attribute">#attribute</a> </ul> </nav> </div> <div id="project-metadata"> <nav id="classindex-section" class="section project-section"> <h3 class="section-header">Class and Module Index</h3> <ul class="link-list"> <li><a href="../LazyStruct.html">LazyStruct</a> <li><a href="../LazyStruct/Mixin.html">LazyStruct::Mixin</a> <li><a href="../Installer.html">Installer</a> <li><a href="../Kernel.html">Kernel</a> </ul> </nav> </div> </nav> <div id="documentation"> <h1 class="module">module LazyStruct::Mixin</h1> <div id="description" class="description"> <p>For mixing into an existing OpenStruct instance singleton class.</p> </div><!-- description --> <section id="5Buntitled-5D" class="documentation-section"> <!-- Methods --> <section id="public-instance-5Buntitled-5D-method-details" class="method-section section"> <h3 class="section-header">Public Instance Methods</h3> <div id="method-i-attribute" class="method-detail "> <div class="method-heading"> <span class="method-name">attribute</span><span class="method-args">(reader, &block)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <p>&block is evaluated when this attribute is requested. The same result is returned for subsquent calls, until the field is assigned a different value.</p> <div class="method-source-code" id="attribute-source"> <pre><span class="ruby-comment"># File install.rb, line 462</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">attribute</span>(<span class="ruby-identifier">reader</span>, &<span class="ruby-identifier">block</span>) <span class="ruby-identifier">singleton</span> = (<span class="ruby-keyword">class</span> <span class="ruby-operator"><<</span> <span class="ruby-keyword">self</span> ; <span class="ruby-keyword">self</span> ; <span class="ruby-keyword">end</span>) <span class="ruby-identifier">singleton</span>.<span class="ruby-identifier">instance_eval</span> { <span class="ruby-comment">#</span> <span class="ruby-comment"># Define a special reader method in the singleton class.</span> <span class="ruby-comment">#</span> <span class="ruby-identifier">define_method</span>(<span class="ruby-identifier">reader</span>) { <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>.<span class="ruby-identifier">tap</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-comment">#</span> <span class="ruby-comment"># The value has been computed. Replace this method with a</span> <span class="ruby-comment"># one-liner giving the value.</span> <span class="ruby-comment">#</span> <span class="ruby-identifier">singleton</span>.<span class="ruby-identifier">instance_eval</span> { <span class="ruby-identifier">remove_method</span>(<span class="ruby-identifier">reader</span>) <span class="ruby-identifier">define_method</span>(<span class="ruby-identifier">reader</span>) { <span class="ruby-identifier">value</span> } } } } <span class="ruby-comment">#</span> <span class="ruby-comment"># Revert to the old OpenStruct behavior when the writer is called.</span> <span class="ruby-comment">#</span> <span class="ruby-identifier">writer</span> = <span class="ruby-node">"#{reader}="</span>.<span class="ruby-identifier">to_sym</span> <span class="ruby-identifier">define_method</span>(<span class="ruby-identifier">writer</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-identifier">singleton</span>.<span class="ruby-identifier">instance_eval</span> { <span class="ruby-identifier">remove_method</span>(<span class="ruby-identifier">reader</span>) <span class="ruby-identifier">remove_method</span>(<span class="ruby-identifier">writer</span>) } <span class="ruby-identifier">method_missing</span>(<span class="ruby-identifier">writer</span>, <span class="ruby-identifier">value</span>) } } <span class="ruby-keyword">end</span></pre> </div><!-- attribute-source --> </div> </div><!-- attribute-method --> </section><!-- public-instance-method-details --> </section><!-- 5Buntitled-5D --> </div><!-- documentation --> <footer id="validator-badges"> <p><a href="http://validator.w3.org/check/referer">[Validate]</a> <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12. <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3. </footer>
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 9254 | Jen Bottom |
updated gemspec and cleaned out doc directory. Will re-generate as part of the Gem build process |
||
#1 | 8366 | Jen Bottom | Adding the source code and docs for the P4Ruby Gem to the Public Depot. |