--f46d0447850b06807204b0c0c74f
Content-Type: text/plain; charset=UTF-8

On Tue, Nov 1, 2011 at 10:13, Michael Kohl <citizen428 / gmail.com> wrote:

> def add_content(k, v)
>  @hash.merge(Hash[k,v]) # or @hash.merge({k v})
> end
>

I think perhaps you want #merge! not #merge.

However, given that this can only take two arguments, the only reason I can
think of for doing it this way is so that you can chain multiple
add_content calls: book.add_content(a, b).add_content(c, d). Otherwise, why
not just define

def [], v)
  @hash[k]  
end

and then you can have book[1]  ? Maybe it doesn't make sense to have a
Book look like a Hash, though, in which case you can define some other foomethod, if that's meaningful. Method name aside, the @hash.merge! approach
would be good if you can have more than one addition in one step:

def add(h  })
  @hash.merge!(h)
end

Which also avoids having to do add_content(a, b).add_content(c, d). #add
seems like it's a bit too generic, but perhaps in the actual code it'll
have a more meaningful name.

--f46d0447850b06807204b0c0c74f--