Skip to content
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

Literal::Array: implement #replace, and #insert. add #prepend alias #142

Merged

Conversation

phillipspc
Copy link
Contributor

@phillipspc phillipspc commented Nov 11, 2024

Continuing to chip away at #134


My goal was to more or less work my way down the list of "Methods for Assigning" from the ruby docs
CleanShot 2024-11-11 at 14 20 07@2x

From that list, this implements:

  • #prepend (alias for #unshift)
  • #insert
  • #replace

I'm still not 100% on if I'm always using Literal.check correctly. And also unsure how thorough to be in tests. Feedback welcome of course!

This is very similar to how `#push` works, except it happens at a given
`index`, and the implementation and tests are also very similar.
@phillipspc phillipspc mentioned this pull request Nov 11, 2024
when Array
value
when Literal::Array
value.to_a
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t know if Array#replace(value) will mutate the given value or just use it as a reference. If it doesn’t mutate, we could call .__value__ here instead of .to_a.

@phillipspc phillipspc force-pushed the more-literal-array-improvements branch from aaad8bd to da58a31 Compare November 11, 2024 21:33
`#replace` should work with either an Array or Literal::Array. It should
raise an ArgumentError for any other class of argument, and it should
enforce type checking.
@phillipspc phillipspc force-pushed the more-literal-array-improvements branch from da58a31 to eb1ed43 Compare November 11, 2024 21:47
@phillipspc phillipspc changed the title Literal::Array: implement #replace, #concat, and #insert. add #prepend alias Literal::Array: implement #replace, and #insert. add #prepend alias Nov 11, 2024
@phillipspc
Copy link
Contributor Author

@joeldrapper Based on our conversation, I've removed the concat attempt for now 😅 . I've also updated replace to hopefully be more in line with what you were looking for. Let me know what you think

@joeldrapper joeldrapper merged commit 42b9bdf into joeldrapper:main Nov 14, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants