Hi all,
I am a newbie in Ruby, and I am having a small question with the hash
table. If anyone could give me some suggestions that would be great!
Considering creating a hash table like this:
a_Min a_Max b_Min b_Max p1 p2 p3
p4
p5 p6
40.000 47.95 -95.0 -74.01 12.8 6.5 177.82 0.9150 68.62
0.9020
42.000 47.95 -68.0 -59.50 11.0 5.8 185.20 0.9377 -11.80
0.9538
44.000 47.95 -74.2 -68.05 12.8 6.5 157.45 0.9194 37.55
0.9297
46.000 66.00 -59.5 -51.00 8.8 3.7 164.96 0.9465 -207.54
1.0342
47.951 66.00 -79.0 -59.55 12.8 6.5 157.45 0.9194 37.55
0.9297
47.951 66.00 -95.0 -79.01 12.8 6.5 177.82 0.9150 68.62
0.9020
…
If giving any (a,b), it will fall within the four boundary control
values
in the hash table (a_Min, a_Max, b_min, b_Max) and returns its relative
parameters (p1, p2, p3…)
I am trying something like this:
def functionXXX(a, b)
threshold = XXX # how to create
a
hash table with the above data?
for t in threshold do
if (t[:a_Min]<=a && a<t[:a_Max] && t[:b_Min]<=b && b<t[:b_Max]) then
#if there is a smarter way in Ruby for this?
return t
break
end
end
end
Would this be the correct way of doing this task in Ruby?
Thanks!
Suo