Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby - undefined method `extract_options!' : Array

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?

like image 994
Amit Patel Avatar asked Oct 25 '25 20:10

Amit Patel


1 Answers

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).

like image 55
K M Rakibul Islam Avatar answered Oct 27 '25 12:10

K M Rakibul Islam