Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Include module Module ActiveSupport::CoreExtensions::Array::Grouping

Reply
Thread Tools

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

 
 
RichardOnRails
Guest
Posts: n/a
 
      03-15-2011
I want to use the grouping method(s) from the subject module, but I
can't translate it address into a ruby include.

The module's documented at http://rails.rubyonrails.org/classes.../Grouping.html.

Thanks in Advance for any guidance offered.
Richard
 
Reply With Quote
 
 
 
 
7stud --
Guest
Posts: n/a
 
      03-16-2011
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.

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
7stud --
Guest
Posts: n/a
 
      03-16-2011
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.

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does Module#include exclude the module's metaclass? John Mair Ruby 8 10-07-2010 12:29 PM
include module in module Ittay Dror Ruby 2 12-08-2008 12:03 PM
How to exec a module method when "include Module" from a Class ? IƱaki Baz Castillo Ruby 3 05-02-2008 09:37 AM
/* #include <someyhing.h> */ => include it or do not include it?That is the question .... Andreas Bogenberger C Programming 3 02-22-2008 10:53 AM
include Module in another Module Brian Buckley Ruby 3 02-20-2007 05:32 AM



Advertisments