Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Here's an example of how I use the hash as keyword arguments. (Minus the documentation

    def save_record(record, options={}, &block)
      return nil if record.nil?
      options = {
        :add_params => {},
        :as => nil,
        :without_protection => false,
        :params => params[record.class.name.underscore.to_sym],
        :user => current_user,
      }.update options
The important part is: options = {}.update(options)

This pattern works very well for providing defaults and some documentation on what options are available. I still document the options before the function.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: