Neville Burnell wrote:
> Hi,
> 
> I have a class inheriting from Hash which has some specific methods
> operating on the hash elements:
> 
> Class MyHash < Hash
> 
>   def foo
>   ...
>   end
> 
> End
> 
>  ....
> 
> Now, with Hash class, its really easy to create a new hash, eg
> 
> h = {:key1 => "val1", :key2 => "val2"}
> 
> What I would like to do is create a new instance of the class with the
> same simplicity, but I'd like to avoid creating a redundant Hash and
> tranferring the contents one by one to MyHash which happens if I code:
> 
> h = MyHash.new(:key1 => "val1", :key2 => "val2")
> 
> and then define initialize(h={})
> 
> Whats the "ruby way" tm for something like this?

irb(main):001:0> class H < Hash
irb(main):002:1>   def foo; "foo"; end
irb(main):003:1>   end
=> nil
irb(main):004:0> h = H[1,2,3,4]
=> {1=>2, 3=>4}
irb(main):005:0> h.class
=> H