/ Published in: Other

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
class Object # provides a params hash which will can useful for testing # USAGE : Model.to_params :name_of_params_hash # => :name_of_params_hash defaults to :params # to override the params hash, just pass a hash list of attributes : # Model.to_params.merge(:my_options => "my_value") def to_params(params_name="params") @@params_var = params_name.to_sym attributes = self.new.attributes.keys.map {|c| c.to_sym} p_hsh = {} attributes.map {|a| p_hsh[a]=nil} params = {@@params_var => p_hsh} params.instance_eval do #overrides Hash#merge method by merging just the sub hash and not the main one def merge(options={}) self[@@params_var].update(options) return self end end return params end end
Comments
