-
-
Save avdi/2662690 to your computer and use it in GitHub Desktop.
ValueObject in Virtus with a custom constructor - proposed
This file contains hidden or 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 'virtus' | |
Point = Struct.new(:x, :y) | |
class Rectangle | |
include Virtus | |
attribute :top_left, Point | |
attribute :bottom_right, Point | |
end | |
rect = Rectangle.new(top_left: [3,5], bottom_right: [8,7]) | |
puts rect.top_left.inspect # => #<Point x=3 y=5> | |
puts rect.bottom_right.inspect # => #<Point x=8 y=7> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@avdi I'm going to make that possible in the upcoming Virtus 0.5.0 :) thanks for inspirations man