From: 7stud -- Date: 2008-02-05T18:00:02+09:00 Subject: Re: How to add string objects to hash? dare ruby wrote: > Dear friends, > > I have created a string buffer. > > I have read character by character from buffer using a method and stored > in a string object > like, > > @test = String.new > > The method iteration process continues till @flag=1. So for every > iteration of method a string object(@test) is returned from the method. > > Now i want to move this returned string object @test into a hash. How > can i move string objects into hash. > > I need to store all strings that are returned(@test) till flag=1 in a > hash. I dont want to use an array to store the values. > > Please help me to do this process. > > Thanks in advance > > Regards, > Jose Martin This is an example of a hash: h = {"a"=>"circle", "b"=>"square", "c"=>"triangle"} puts h["a"] --output:-- circle Note that every element of a hash is a key/value pair. You say, "I want to put my strings into a hash", but the elements of a hash are not single objects--the elements of a hash are pairs of objects. If your strings are to be the values, what do you want to be the keys? -- Posted via http://www.ruby-forum.com/.