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
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?
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