# Creating array, decimal

Hi
I have an attribute decimal => hour

If I do

hours.each do |h|
h.my_hour
end
I get => 20.0 0.0 0.0 10.0

And this…
myhour = []
hours.each do |h|
myhour << hour
end
myhour.join(",")

I get =>
Hour:0x007f81feec3330,#Hour:0x007f81feaa0c30,

How do I get something like this ?
20.0, 0.0, 0.0, 10.0

Thanks for support

override Hour’s to_s method to return my_hour

Thanks…but
mhhh…it is not clear what you mean…

hour.join(",").to_s ???
no effect…

Matt's

Thanks..but
mhhh..it is not clear what you mean...

hour.join(",").to_s ???
no effect…

override Hour's to_s method to return my_hour

--
Dheeraj Kumar

Hi
I have an attribute decimal => hour

If I do

hours.each do |h|
h.my_hour
end
I get => 20.0 0.0 0.0 10.0

And this..
myhour = []
hours.each do |h|
myhour << hour

Here is the problem:

myhour << h.my_hours

Well my be I am a litte stubborn today…
What I need is an array

[20.0, 0.0, 0.0, 10.0]

this work for me:

hours.collect{|h| h.my_hour}

or

hours.map(&:my_hour)

After chaning the datatype to integer…
yes…works

but as decimal (6,2)
stays : Hour:0x007f81feec3330,#Hour:0x007f81feaa0c30,

Thanks so far

Hi
I have an attribute decimal => hour

If I do

hours.each do |h|
h.my_hour
end
I get => 20.0 0.0 0.0 10.0

And this..
myhour = []
hours.each do |h|
myhour << hour

That should be
myhour << h.myhour
though myhour is a very poor name for an array. It should be plural.

end
myhour.join(",")

I get =>
<Hour:0x007f81feec3330>,#<Hour:0x007f81feaa0c30>,

That it because you are adding Hour objects into the array, not decimal objects.

Colin

Hi
I have an attribute decimal => hour

If I do

hours.each do |h|
h.my_hour
end
I get => 20.0 0.0 0.0 10.0

And this..
myhour = []
hours.each do |h|
myhour << hour

That should be
myhour << h.myhour
though myhour is a very poor name for an array. It should be plural.

end
myhour.join(",")

I get =>
<Hour:0x007f81feec3330>,#<Hour:0x007f81feaa0c30>,

That it because you are adding Hour objects into the array, not decimal objects.

o.k..
true..

Thanks

Carlos did point out the problem earlier. It is worth reading the answers
carefully when you ask a question.

Colin