Skip to content

Instantly share code, notes, and snippets.

@cecyc
Created March 8, 2022 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cecyc/2d1dff2b92a102047fb5f118e70e1c20 to your computer and use it in GitHub Desktop.
Save cecyc/2d1dff2b92a102047fb5f118e70e1c20 to your computer and use it in GitHub Desktop.
Example of SmartProperties in Ruby
require "smart_properties"
require "date"
class User
include SmartProperties
property! :email, accepts: String, converts: :to_s
property :dob, accepts: Date
property :zip_code, accepts: [90210, 48378, 93893, 94238]
end
# valid
User.new(email: "user@example.com", dob: Date.new(2000, 1, 2), zip_code: 94238)
# invalid
User.new(dob: "2000/01/02", zip_code: 11111)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment