From: Robert Klemme Date: 2011-10-02T04:02:06+09:00 Subject: Re: access hashmap objects On Sat, Oct 1, 2011 at 3:28 PM, Sam s. wrote: > I got objects inside of a hashmap. And they are packed as the following > code says and I want to unpack them again to change their manipulate the > data and pack it again in the same way. Or directly change each datum if > that works. > > mutation_map = key => { >          column_family => hash.collect{|k,v| > _standard_insert_mutation(column_family, k, v, timestamp, > options[:ttl])} >        } That's not a Hash but rather a partial description of how a Hash is created. > def _standard_insert_mutation(column_family, column_name, value, > timestamp, ttl = nil) >      CassandraThrift::Mutation.new( >        :column_or_supercolumn => > CassandraThrift::ColumnOrSuperColumn.new( >          :column => CassandraThrift::Column.new( >            :name      => > column_name_class(column_family).new(column_name).to_s, >            :value     => value, >            :timestamp => timestamp, >            :ttl       => ttl >          ) >        ) > Code from the fauna project on github. A ruby cassandra client. > > now I think I understand what happens in this bit of code, but if I have > this mutation_map later in code and want to manipulate specific parts of > it how would I do that. > Like encrypting the whole map. I would need access to each bit and > change it A fairly simply way to do it would be to serialize it via Marshal and encrypt the resulting binary sting. > getting to the column_family I write mutation_map[key][column_family] > How do I go from there? I have an object now and this object should have > accessor methodes. > > I know java not as much about ruby. How do I access that data. Should > simple for any ruby veteran but in all the tutorials they stick to such > simple stuff that you don't learn this kind of things. I am not sure what you are really up to. Accessing members of a Hash is fairly straightforward - for reading and writing. You can easily extend that to nested Hashes irb(main):003:0> h={:k => {:j => {}}} => {:k=>{:j=>{}}} irb(main):004:0> h[:k][:j][:i] = 123 => 123 irb(main):005:0> h => {:k=>{:j=>{:i=>123}}} Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/