Skip to content

Instantly share code, notes, and snippets.

@astagi
Last active September 27, 2018 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astagi/2e109aa6cbc8db3abcc9e660227ab667 to your computer and use it in GitHub Desktop.
Save astagi/2e109aa6cbc8db3abcc9e660227ab667 to your computer and use it in GitHub Desktop.
Try to use macro
module Ansa
private
# @!macro [attach] generate_get_news
# @method get_$1_news
# @!scope class
# @note This method is autogenerated
# Get news for "$1" category.
# @raise [Ansa::AnsaError] when errors occour fetching news
# @return [Array<Ansa::News>] all the news of category "$1".
def self.generate_get_news(category, url)
define_singleton_method("get_#{category}_news") do
get_news_by_url(url)
end
end
public
generate_get_news 'soccer', 'the_soccer_url.xml'
generate_get_news 'politics', 'the_politics_url.xml'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment