You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Contracts has "Array" and "ArrayOf". ArrayOf is created using the Contracts::CollectionOf::Factory.new(UserClass) and the class passed in needs to support Array-like operations.
It has "Hash" and "HashOf". It supports a UserClass that is subclassed from Hash (that is, there doesn't appear to be a way to supply an arbitrary user class that provides Hash-like operations.
That is, I want to specify a Contract like: nil => HashOf[String,Integer], but pass in my own user class.
Am I missing a way to do this in today's gem?
The text was updated successfully, but these errors were encountered:
You would have to write this yourself. For example:
require"hashie"require"contracts"includeContractsclassMashOfdefself.valid?mashmash.eachdo |k,v|
returnfalseunlessk.is_a?(String) && v.is_a?(Numeric)endendendContractMashOf=>Stringdeffoox"hi"endmash=Hashie::Mash.newmash.age=30foomash# no errormash.name="arthur"foomash# error, all vals must be numeric
Contracts has "Array" and "ArrayOf". ArrayOf is created using the Contracts::CollectionOf::Factory.new(UserClass) and the class passed in needs to support Array-like operations.
It has "Hash" and "HashOf". It supports a UserClass that is subclassed from Hash (that is, there doesn't appear to be a way to supply an arbitrary user class that provides Hash-like operations.
That is, I want to specify a Contract like: nil => HashOf[String,Integer], but pass in my own user class.
Am I missing a way to do this in today's gem?
The text was updated successfully, but these errors were encountered: