Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby Quick Class Instance Scope
    primarykey
    data
    text
    <p>I have a quick problem that probably comes down to something stupid. I have a class that extends <code>OAuth::AccessToken</code> and uses instance variables (<code>@</code>) so that each time it constructs an object, those variables will be unique that instance. However, when I try to return the final object from this class, I get an error. A quick example:</p> <pre><code>require 'oauth' class OauthFigshare &lt; OAuth::AccessToken def initialize (consumerkey, consumersecret, accesstoken, accesstokensecret) @consumerkey = consumerkey @consumersecret = consumersecret @accesstoken = accesstoken @accesstokensecret = accesstokensecret @apiurl = "http://api.figshare.com" @consumer = OAuth::Consumer.new(@consumerkey,@consumersecret,{:site=&gt; @apiurl}) @token = { :oauth_token =&gt; @accesstoken, :oauth_token_secret =&gt; @accesstokensecret} puts @consumer.class puts @token @client = OAuth::AccessToken.from_hash(@consumer, @token) puts @client puts @client.get('/v1/my_data/articles') return @client end end </code></pre> <p>The problem is that when I check inside the class to see if the token is working, it does. However, when I check against the constructed object outside the class, it doesn't work.</p> <p><code>@client.get(url) returns Net::HTTPOk</code> calling from in the class</p> <pre><code>auth = OauthFigshare.new(inputs) auth.get(url) </code></pre> <p>This returns <code>Net::HTTPUnauthorized</code></p> <p>What am I not getting about scope here?</p> <p><strong>Edit to include actual class</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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