ruby - Is it possible to conditionally add item to OpenStruct? -


i want add string openstruct this:

link = link.split(",") openstruct.new(title: link[0].strip, url: link[1].strip) 

sometimes, contains third variable, want add well:

openstruct.new(title: link[0].strip, url: link[1].strip, id: link[2].strip) 

i check link[2] , create 2 openstruct.news lines, there way add id afterwards?

prepare hash , modify that conditionally. unconditionally pass openstruct.

link = link.split(',') os_args = { title: link[0].strip, url: link[1].strip } os_args[:id] = link[2].strip if link[2]  openstruct.new(os_args) 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -