virtus icon indicating copy to clipboard operation
virtus copied to clipboard

Attribute should check the arity of the supplied default

Open elskwid opened this issue 12 years ago • 0 comments

From @dkubb in #221:

".. virtus should inspect the arity of the object it's about to call. If the arity is 0, then it should not bother passing in anything.

This would allow use to use normal method objects, eg:

require 'virtus'
require 'securerandom'

class User
  include Virtus.model

  attribute :name,  String
  attribute :token, String, default: SecureRandom.method(:hex)
end

In your specific example it could allow you to do this: (assuming api_key was an actual method and not something handled by #method_missing)

attribute :api_key, String, default: Ebay.config.method(:api_key)

... which I think would be quite elegant.

elskwid avatar Oct 26 '13 04:10 elskwid