Musings on module/class definition domains

  • Thread starter trans. (T. Onoma)
  • Start date
T

trans. (T. Onoma)

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.
 
T

trans. (T. Onoma)

On Thursday 07 October 2004 01:54 am, Martin DeMello wrote:
| > extended
| > def bar
| > puts "Class Method && Instance Method"
| > end
|
| What would the value of 'self' be?

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.
 
M

Martin DeMello

trans. (T. Onoma) said:
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
 
M

Mauricio Fernández

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?

Math::sin 1
include Math
sin 1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top