Note that there are some explanatory texts on larger screens.

plurals
  1. PORubymotion: NoMethodError for added method
    text
    copied!<p>I added an extra method to the String class. I want to use this method later on, but I get a no Method error.</p> <pre><code>class String def as_file_full_path NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true) [0].stringByAppendingPathComponent(self) end end </code></pre> <p>When I try the following in the REPL it works:</p> <pre><code> (main)&gt; "image.jpg".as_full_path =&gt; "/Users/user/Library/Application Support/iPhone Simulator/6.1/Applications/30D186A9-B1C7-4377-AE91-0D14BD3B4A6D/Documents/image.jpg" </code></pre> <p>But when I call a method on a my model class, it does not work anymore:</p> <pre><code> (main)&gt; w = Word.first =&gt; #&lt;Word:0x94d7df0&gt; (main)&gt; w.filename =&gt; "2C86A58A-A92A-4A0F-B26C-0F5F583E142C.caf" (main)&gt; w.filename.class =&gt; String (main)&gt; w.filename.as_full_path 2013-02-28 09:17:55.935 project[74283:c07] undefined method `as_full_path' for "2C86A58A-A92A-4A0F-B26C-0F5F583E142C.caf":String (NoMethodError) =&gt; NoMethodError: undefined method `as_full_path' for "2C86A58A-A92A-4A0F-B26C-0F5F583E142C.caf":String </code></pre> <p>The model is implemented using NanoStore::Model.</p> <p>Edit:</p> <p>When I clone the String returned by the model, the added method <em>is</em> present.</p> <pre><code>w.filename.dup.as_full_path =&gt; "/Users/user/Library/Application Support/iPhone Simulator/6.1/Applications/30D186A9-B1C7-4377-AE91-0D14BD3B4A6D/Documents/2C86A58A-A92A-4A0F-B26C-0F5F583E142C.caf" </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload