Ruby Module in ROR

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

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

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