warning: default `to_a’ will be obsolete

ruby

Apparently Object.to_a will eventually be obsolete (not sure when).  I was using it in the following context:

def foo(args)
  args.to_a.join(',')
end

According to this very old ruby-lang thread, this [*args] is a suitable alternative:

def foo(args)
  [*args].join(',')
end
No Comments »

ActiveYahoo: A Ruby API for Yahoo! Web Services

ruby

Do you Yahoo? I do, and was recently a little disappointed in the Ruby offerings for the Yahoo Web Services API. So, a little coding and we have ActiveYahoo:

require 'active_yahoo'
y = ActiveYahoo::WebSearch.new(‘YOUR_APP_ID’, ‘ruby’, { :results => 2 })
y.result.total_results_returned  # => 2
y.result.records[0].title  # => "Ruby-lang.org"
y.result.records.map { |r| r.url }
#  =>  ["http://www.ruby-lang.org/en", "http://en.wikipedia.org/wiki/Ruby_programming_language"]

A primary objective of ActiveYahoo is to encapsulate Yahoo‘s responses into their own objects. For example, an instance of the WebSearch class will return a WebSearchResult object. Special care is also given to convert response fields into appropriate Ruby data types.

So far, the following Search services have been implemented: Web, News, Images, Audio, and Video. More will follow soon. The essentials are on Rubyforge here:

View the ActiveYahoo project page
View the documentation

No Comments »
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in