# Ruby Module in ROR

**URL:** <https://www.ruby-forum.com/t/ruby-module-in-ror/91704>\
**Category:** Rails\
**Created:** [April 11, 2007, 7:00pm UTC](https://www.ruby-forum.com/t/ruby-module-in-ror/91704 "2007-04-11T19:00:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ccd318/32.png) [@rama](https://www.ruby-forum.com/u/rama)\
**Post date:** [April 11, 2007, 7:00pm UTC](https://www.ruby-forum.com/t/ruby-module-in-ror/91704/1 "2007-04-11T19:00:16Z")

</div>

# in Ruby module “D3” i have defined :

# def dumpAttributes(strPrefix = “”) @attributes.each\_pair do | key, value | puts “#{strPrefix}#{key} : #{value}” end end

and in my Controller when i use :  
@mdb.dumpAttributes("==\> ")

i can see in radrail console that i get all values with key printed  
using puts, but instead of puts i want to store in some array so tht i  
can use same arry in my view

Can anyone suggest me how i can use “key,value” from method into my  
controller.

Iam not good in ROR , so iam sorry if it’s a silly question.

Help me.

Rama

---

<div class="post-metadata">

**Author:** ![rama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ccd318/32.png) [@rama](https://www.ruby-forum.com/u/rama)\
**Post date:** [April 11, 2007, 7:10pm UTC](https://www.ruby-forum.com/t/ruby-module-in-ror/91704/2 "2007-04-11T19:10:27Z")

</div>

Rama S. wrote:

> # in Ruby module “D3” i have defined :
> 
> # def dumpAttributes(strPrefix = “”) @attributes.each\_pair do | key, value | puts “#{strPrefix}#{key} : #{value}” end end
> 
> and in my Controller when i use :  
> @mdb.dumpAttributes("==\> ")
> 
> i can see in radrail console that i get all values with key printed  
> using puts, but instead of puts i want to store in some array so tht i  
> can use same arry in my view
> 
> Can anyone suggest me how i can use “key,value” from method into my  
> controller.
> 
> Iam not good in ROR , so iam sorry if it’s a silly question.
> 
> Help me.
> 
> Rama

Assuming that @attributes is a Hash:

def dumpAttributes(strPrefix = “”)  
@attributes.collect do |key,value|  
“#{strPrefix}#{key} : #{value}”  
end  
end

Collect is like each\_pair but returns an Array the block (do … end)  
evaluation results.

Have fun  
Skade

---

<div class="post-metadata">

**Author:** ![rama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ccd318/32.png) [@rama](https://www.ruby-forum.com/u/rama)\
**Post date:** [April 11, 2007, 7:23pm UTC](https://www.ruby-forum.com/t/ruby-module-in-ror/91704/3 "2007-04-11T19:23:35Z")

</div>

Florian G. wrote:

> Rama S. wrote:
> 
> > # in Ruby module “D3” i have defined :
> > 
> > # def dumpAttributes(strPrefix = “”) @attributes.each\_pair do | key, value | puts “#{strPrefix}#{key} : #{value}” end end
> > 
> > and in my Controller when i use :  
> > @mdb.dumpAttributes("==\> ")
> > 
> > i can see in radrail console that i get all values with key printed  
> > using puts, but instead of puts i want to store in some array so tht i  
> > can use same arry in my view
> > 
> > Can anyone suggest me how i can use “key,value” from method into my  
> > controller.
> > 
> > Iam not good in ROR , so iam sorry if it’s a silly question.
> > 
> > Help me.
> > 
> > Rama
> 
> Assuming that @attributes is a Hash:
> 
> def dumpAttributes(strPrefix = “”)  
> @attributes.collect do |key,value|  
> “#{strPrefix}#{key} : #{value}”  
> end  
> end
> 
> Collect is like each\_pair but returns an Array the block (do … end)  
> evaluation results.
> 
> Have fun  
> Skade  
> Thanks Skade for your help,  
> but still i need help in more depth, dumpAttributes() is in another file  
> “x.rb”…i have included this file.  
> I want to bring values in an array form to use in my controller.  
> So my question is how i can store “key,value” in array, and how to get  
> tht array in my controller

Rama
