If the expected return value is different between the class and the
instance methods, then you really do want two separate methods. However, if
they will always be defined with identical code, you can put the code into
a module, and then 'include' and 'extend' that module into your class to
get both a class and an instance method.

I am typing on my phone now, so I will leave you to look up include and
extend if you are unsure how they work. I hope this helps.


Kirk Haines

On Dec 5, 2016 7:19 AM, "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.
>
> Le lun. 5 dc. 2016  15:11, Aleksey Ivanov <ialexxei / gmail.com> a crit :
>
>> def self.tag_list
>>   list = {}
>>   tag_types.each do |context|
>>     list[context] = tags_on(context)
>>   end
>>   list
>> end
>>
>> you definitely should use reduce
>>
>> def self.tag_list
>>   tag_types.reduce({}) do |memo, context|
>>     list.merge context => tags_on(context)
>>   end
>> end
>>
>> On Mon, Dec 5, 2016 at 5:06 PM, Kirk Haines <wyhaines / gmail.com> wrote:
>>
>> On Mon, Dec 5, 2016 at 5:34 AM, Terry Raimondo <terry.raimondo / gmail.com>
>> wrote:
>>
>>
>> def self.tag_list
>>   list = {}
>>   tag_types.each do |context|
>>     list[context] = tags_on(context)
>>   end
>>   list
>> end
>>
>> def tag_list
>>   list = {}
>>   tag_types.each do |context|
>>     list[context] = tags_on(context)
>>   end
>>   list
>> end
>>
>>
>>
>>
>> def self.tag_list
>>   list = {}
>>   tag_types.each do |context|
>>     list[context] = tags_on(context)
>>   end
>>   list
>> end
>>
>> def tag_list
>>   self.class.tag_list
>> end
>>
>>
>> Kirk Haines
>>
>>
>> Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
>> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
>>
>>
>>
>> Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
>> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
>>
> --
> Terry Raimondo
>
>
> Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
>
>
(supressed text/html)
Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>