[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: How to read values dynamically

???

9/13/2007 7:26:00 AM

Hi, here is a instance for read values dynamically

class Test

A_HASH = {"key1"=>value1,"key2"=>value2}

A_HASH.each_key do |key|
module_eval <<-EOF
def #{key}
find :all,:conditions=>[" attribute = ?",Test::A_HASH[#{key}]]
end
EOF
end
end

You see ,it really dynamical.

Best Regards.

Tim


1 Answer

barjunk

9/13/2007 4:11:00 PM

0

On Sep 12, 11:26 pm, "Tim.Teng" <tengxiangg...@gmail.com> wrote:
> Hi, here is a instance for read values dynamically
>
> class Test
>
> A_HASH = {"key1"=>value1,"key2"=>value2}
>
> A_HASH.each_key do |key|
> module_eval <<-EOF
> def #{key}
> find :all,:conditions=>[" attribute = ?",Test::A_HASH[#{key}]]
> end
> EOF
> end
> end
>
> You see ,it really dynamical.
>
> Best Regards.
>
> Tim

You can use YAML, which folks seem to like for its flexibility.

Mike B.