Created
March 8, 2022 23:05
-
-
Save cecyc/2d1dff2b92a102047fb5f118e70e1c20 to your computer and use it in GitHub Desktop.
Example of SmartProperties in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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