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 []=(k, v)
  @hash[k] = v
end

and then you can have book[1] = 2? Maybe it doesn't make sense to have a
Book look like a Hash, though, in which case you can define some other foo=
method, 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.