Is there an opposite function of slice function in Ruby?

后端 未结 3 507
清酒与你
清酒与你 2021-02-05 00:07

In this post, slice function is used to get only necessary elements of params. What would be the function I should use to exclude an element of params (such as user_id)?

3条回答
  •  名媛妹妹
    2021-02-05 00:44

    Try this

    params = { :title => "title", :other => "other", :body => "body"  }
    
    params.select {|k,v| [:title, :body].include? k  } #=> {:title => "title", :body => "body"}  
    

提交回复
热议问题