On Sep 7, 10:52=A0am, Stephen Celis <stephen.ce... / gmail.com> wrote:
> Hi,
>
> On Sep 7, 2008, at 9:05 AM, Trans wrote:
>
> > def grumpize
> > =A0 to_self(to_s.upcase + '!!!!!!!!!')
> > end
>
> This is a bit of a confusing idiom, especially when expanded:
>
> =A0 =A0self.to_self(self.to_s.upcase + '!!!!!!!!!')
>
> You may make yourself slightly clearer with a block method. A =A0
> simplified example:
>
> =A0 =A0class Object
> =A0 =A0 =A0def returning_initial_class(&block)
> =A0 =A0 =A0 =A0yield(self).__send__ case self
> =A0 =A0 =A0 =A0 =A0when String then :to_s
> =A0 =A0 =A0 =A0 =A0when Symbol then :to_sym
> =A0 =A0 =A0 =A0end
> =A0 =A0 =A0end
> =A0 =A0end
>
> =A0 =A0module Grumpy
> =A0 =A0 =A0def grumpize
> =A0 =A0 =A0 =A0returning_initial_class { |grump| grump.to_s.upcase + =A0
> '!!!!!!!!!' }
> =A0 =A0 =A0end
> =A0 =A0end
>
> It's cleanest to just define String#grumpize and Symbol#grumpize =A0
> individually.

Ah, that helps me "cleanest" my thoughts. It occurs to me that while
#to_self() makes sense in this context, it may differ depending on the
mixin used. For example:

  class Integer
    include Grumpy
  end

That could work, but if to_self is used there will be issues clearly
(!!!!!!!!! ain't a number). Hence, what I'm really after is an
optional method that can be defined when needed to say "how to become
grumpy". Then:

  module Grumpy
    def make_grumpy(obj)
      obj
    end

    def grumpize
      make_grumpy(to_s.upcase + '!!!!!!!!!')
    end
  end

  class Symbol
    include Grumpy
    def make_grumpy(obj)
      obj.to_sym
    end
  end

T.