Include module Module ActiveSupport::CoreExtensions::Array::Grouping

7

7stud --

require "<your path to
here->/lib/active_support/core_ext/array/grouping"

Then you will have something like this at the top of your file:

module A
module B
module C

def in_group
puts "in_group"
end

end
end
end


Which means you can do this:

class MyClass
include A::B::C
end

MyClass.new.in_group

--output:--
in_group


I think that Grouping is defined as a "mixin" module--in other words it
is a module which contains regular def's inside it:

module ActiveSupport
module CoreExtension
module Array
module Grouping

def in_group
..
..
end

end
end
end
end


You can't create a module instance, like you can with a class. So you
are not able to create a Grouping instance:

obj = Grouping.new

and call the method using the instance:

obj.in_group

Rather mixin modules are created to be included by a class, and then the
defs in the module become defs in the class.
 
7

7stud --

Or, you can also do something like this:

module A
module B
module C

def in_group
puts 'in_group'
end

end
end
end


include A::B::C
in_group

include() at the top-level causes the defs in the module to be included
in the Object class, which means you can call in_group (without a
receiver) from anywhere.
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top