Aim: perform a method chaining based on hash
Required operation:
ErrorLog.event_eq([3, 7]).subdomain_like("default").user_id_eq(100)
Given:
search_opts = { :event_eq => [3, 7], :subdomain_like => "default", :user_id_eq => 100 }
Solution:
search_opts.inject(ErrorLog) { |memo, (k, v)| memo.send(k, v) }This tip was submitted by sumskyi.
You can use HTML tags for formatting. Wrap code in <code> tags and multiple lines of code in <pre><code> tags.