newbie mixin question

M

Michael Garriss

Hi,
Just 2 questions:

1) How can I mixin a class method (not an instance method)?

2) How can I force a certain method to be called when the an object of a
class that includes that module is initialized? Sort of like a mixin
initialize....

TIA
Michael Garriss
 
J

Joel VanderWerf

Michael said:
2) How can I force a certain method to be called when the an object of a
class that includes that module is initialized? Sort of like a mixin
initialize....

Define initialize in the module, and call super from the class which
mixes it in.
 
Y

Yukihiro Matsumoto

Hi,

In message "newbie mixin question"

|1) How can I mixin a class method (not an instance method)?

module Foo
def foo
p "foo"
end
end

class Bar
Bar.extend(Foo)
end

Bar.foo

matz.
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top