extract_options!
is ActiveSupport method. If it's not rails app you need to install it and include into script.
Ruby - undefined method `extract_options!' : Array
-
07-12-2021 - |
Question
While running following sample using TweetStream I am getting mentioned error.
tweets.rb
require 'tweetstream'
TweetStream.configure do |config|
config.consumer_key = '<CONSUMER KEY>'
config.consumer_secret = '<CONSUMER SECRET>'
config.oauth_token = '<OAUTH TOKEN>'
config.oauth_token_secret = '<OAUTH TOKEN SECRET'
config.auth_method = :oauth
end
TweetStream::Client.new.track('ruby') do |status|
puts "#{status.text}"
end
Error
$ ruby tweets.rb
/home/amit/.rvm/gems/ruby-1.9.3-p194/gems/tweetstream-2.3.0/lib/tweetstream/client.rb:96:in `track': undefined method `extract_options!' for ["ruby"]:Array (NoMethodError)
from tweets.rb:11:in `<main>'
https://github.com/intridea/tweetstream
Am I missing something?
Solution 2
OTHER TIPS
Here's another solution: opening up Array
class and defining extract_options!
method on it.
Add the following code :
class Array
def extract_options!
last.is_a?(::Hash) ? pop : {}
end unless defined? Array.new.extract_options!
end
to the beginning of the tweets.rb
file or to a separate file (which would
need to be required in the tweets.rb
file).
I am too late to answer but i think it'll be useful for ruby naive programmers like me.
To include ActiveSupport method like extract_options!, you need to include Active Support.
require 'active_support'
And if you want to include ruby gems then include rubygems too.
require 'rubygems'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow