From: Steve Klabnik Date: 2010-02-05T08:05:22+09:00 Subject: Re: Can Ruby Do This? --001485f7d648005f09047ece5d60 Content-Type: text/plain; charset=ISO-8859-1 $ irb irb(main):001:0> hash[:foo][:bar][:baz] = 123 NoMethodError: undefined method `[]' for nil:NilClass from (irb):1 from /usr/bin/irb:12:in `
' irb(main):002:0> hash = { :foo => { :bar => { :baz => 123} } } => {:foo=>{:bar=>{:baz=>123}}} irb(main):003:0> hash[:foo][:bar][:baz] => 123 I'm not sure if there's a way that's a little less verbose... On Thu, Feb 4, 2010 at 10:58 PM, Mr Bubb wrote: > In Perl, you can create a hash of arbitrary depth like so: > > $hash->{foo}->{bar}->{baz} = 123; > > I've tried this in ruby: > > hash[:foo][:bar][:baz] = 123 > > but I get nil.= errors > > I could of course do a check for null at each level, but oy, that's so > cumbersome. Is there a ruby way? > > Thanks! > -- > Posted via http://www.ruby-forum.com/. > > --001485f7d648005f09047ece5d60--