Answer the question
In order to leave comments, you need to log in
How to pass global variables to do block?
Get config from file
$app_settings = YAML.load_file("#{File.dirname(__FILE__)}/settings.yml")
def initialize
@client = Twitter::REST::Client.new do |config|
config.consumer_key = $app_settings[:twitter][:api_key]
config.consumer_secret = $app_settings[:twitter][:api_secret]
config.access_token = $app_settings[:twitter][:access_token]
config.access_token_secret = $app_settings[:twitter][:access_token_secret]
end
end
Answer the question
In order to leave comments, you need to log in
In what class? What do you get? How can you not get it out?
See what's in the variable. Perhaps it is initialized later than the twitter client. Perhaps there is a different structure. Perhaps you need to specify strings instead of characters as keys
Alternatively, the problem may be in scope. When creating an instance of a class, try to write a reference to the variable into some property of the object.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question