Musings on module/class definition domains

I find Ruby's various means of accessing class "domain" a bit clunky. Between
class << self, extend self, module_function, def AClass.foo, def self.foo,
and so forth. So I muse on what might be more uniform and easily
comprehensible.

  class Example
    metaclass
      def foo
        puts "Class Method"
      end
    instance
      def foo
        puts "Instance Method"
      end
    extended
      def bar
        puts "Class Method && Instance Method"
      end
  end

And with variations:

  class Example
    instance private
      def foo
        puts "Instance Method"
      end
    extended instance private # just like module_function
      def bar
        puts "Class Method && Instance Method"
      end
  end

T.

What would the value of 'self' be?

martin

···

"trans. (T. Onoma)" <transami@runbox.com> wrote:

    extended
      def bar
        puts "Class Method && Instance Method"
      end

Sorry, I should have clarified what his means. The above is basically the same
as currently doing:

    extend self
    def bar
      puts "Class Method && Instance Method"
    end

Which is why I called it extended. It is almost, but not quite, the same thing
as doing:

  metaclass
    def bar
      puts "Class Method && Instance Method"
    end
  instance
    def bar
      puts "Class Method && Instance Method"
    end

Does that answer the question, or am I misunderstanding?

T.

···

On Thursday 07 October 2004 01:54 am, Martin DeMello wrote:

"trans. (T. Onoma)" <transami@runbox.com> wrote:
> extended
> def bar
> puts "Class Method && Instance Method"
> end

What would the value of 'self' be?

as doing:

  metaclass
    def bar
      puts "Class Method && Instance Method"
    end
  instance
    def bar
      puts "Class Method && Instance Method"
    end

Does that answer the question, or am I misunderstanding?

I was just wondering about the utility of a method that got attached
both to the class and the instance, since the value of 'self' would be
very different in each case. Can you give me an example?

martin

···

"trans. (T. Onoma)" <transami@runbox.com> wrote:

Math::sin 1
include Math
sin 1

···

On Fri, Oct 08, 2004 at 03:14:46PM +0900, Martin DeMello wrote:

"trans. (T. Onoma)" <transami@runbox.com> wrote:
as doing:
>
> metaclass
> def bar
> puts "Class Method && Instance Method"
> end
> instance
> def bar
> puts "Class Method && Instance Method"
> end
>
> Does that answer the question, or am I misunderstanding?

I was just wondering about the utility of a method that got attached
both to the class and the instance, since the value of 'self' would be
very different in each case. Can you give me an example?

--
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com