-
-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prototype Literal::Array #133
Conversation
600bf25
to
3764c17
Compare
lib/literal/array.rb
Outdated
def initialize(type, value) | ||
unless Array === value && value.all?(type) | ||
raise | ||
end | ||
|
||
@__type__ = type | ||
@__value__ = value | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably allocate and call another method because this shouldn’t be called directly by a user.
def new(*value) | ||
Literal::Array.new(@type, value) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This importantly makes a copy of the array since it picks up the splat. This is essential to maintain the integrity of the array, since otherwise it could be mutated elsewhere. This value should never be exposed. Even to_a
should only expose a duplicate.
I’m going to merge this now so work on other methods can be parallelised. |
Initial stab at ##134.