On Mon, Dec 5, 2016 at 3:18 PM, Terry Raimondo <terry.raimondo / gmail.com> wrote:
> The point is `self.tag_types` and `instance.tag_types` won't return the same
> thing.
> It is really important to keep the respective behavior for self and
> instance.
> If I use one the methods above it will only work for the class method.

module TagAlgorithms
  def tag_list
    {}.tap do |list|
      tag_types.each do |context|
        list[context] = tags_on(context)
      end
    end
  end
end

class YourClass
  include TagAlgorithms
  extend TagAlgorithms
end

Now you can do

instance = YourClass.new
...
instance.tag_list

as well as

YourClass.tag_list

Btw, I would consider the method name a misnomer as it does not return
a list but a Hash.

Kind regards

robert

-- 
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/

Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>