Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #3485

Re: How to split dot “.” only before equal “=”

From 7stud -- <bbxx789_05ss@yahoo.com>
Newsgroups comp.lang.ruby
Subject Re: How to split dot “.” only before equal “=”
Date 2011-04-25 19:46 -0500
Organization Service de news de lacave.net
Message-ID <d9fe0ee748ddc101bcee7888c640c607@ruby-forum.com> (permalink)
References <18aacfcb7224df848f220e5e5c060ee9@ruby-forum.com> <2bcb1fea255cf99800791245bd83bfac@ruby-forum.com> <767901e2edc9e860b36205e0197f978f@ruby-forum.com>

Show all headers | View raw


7stud -- wrote in post #994963:
>

..and you can even get rid of that ugly if check every time through the 
loop:


str = 'projects.risks.Index.flash_downloading=Downloading.test'

key_str, val = str.split('=')
keys = key_str.split(/[.]/)

temp = master = {}
last = keys.pop

keys.each do |key|
  temp = temp[key] = {}
end

temp[last] = val

p master

--output:--
{"projects"=>{"risks"=>{"Index"=>{"flash_downloading"=>"Downloading.test"}}}}

-- 
Posted via http://www.ruby-forum.com/.

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to split dot “.” only before equal  “=” Sira PS <ploy.sukachai@gmail.com> - 2011-04-23 12:05 -0500
  Re: How to split dot “.” only before  equal “=” 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-23 12:08 -0500
  Re: How to split dot “.” only before  equal “=” Sira PS <ploy.sukachai@gmail.com> - 2011-04-23 12:31 -0500
    Re: How to split dot “. ” only before equal “=” Roy Zuo <roylzuo@gmail.com> - 2011-04-23 12:38 -0500
      Re: How to split dot “.” only before equal “= ” Robert Dober <robert.dober@gmail.com> - 2011-04-24 02:33 -0500
        Re: How to split dot “.” only before equal “= ” Robert Dober <robert.dober@gmail.com> - 2011-04-24 03:09 -0500
    Re: How to split dot “.” only before  equal “=” 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-23 17:57 -0500
    Re: How to split dot “.” only before  equal “=” 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-25 16:27 -0500
      Re: How to split dot “.” only before  equal “=” 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-25 19:46 -0500
  Re: How to split dot “.” only before  equal “=” Sira PS <ploy.sukachai@gmail.com> - 2011-04-24 03:02 -0500

csiph-web