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

Fix #3125: Added documentation for printf in the MemoryIO class #3126

Conversation

abhijitiitr
Copy link

@abhijitiitr abhijitiitr commented Aug 9, 2016

Adding the documentation for printf in the MemoryIO class to fix this issue

@jhass
Copy link
Member

jhass commented Aug 9, 2016

It probably should list the available specifiers, the implementation is at https://github.com/crystal-lang/crystal/blob/master/src/string/formatter.cr

@abhijitiitr
Copy link
Author

@jhass Okay. I'll write the available specifiers. Should I also write about the error thrown in case the number of arguments are less than the number of specifiers

@jhass
Copy link
Member

jhass commented Aug 9, 2016

Yes, sure, sounds good.

… arguments to the documentation of printf in MemoryIO class
# %i => decimal
# %x => hexadecimal
# %X => hexadecimal
# %a, %A, %e, %E, %f, %g, %G => char
Copy link
Member

Choose a reason for hiding this comment

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

I think mentioning the possible input types and giving an example would be good. Also mentioning %{foo} and %<foo>d. Finally the flags and modifiers for those that take it.

Copy link
Author

@abhijitiitr abhijitiitr Aug 9, 2016

Choose a reason for hiding this comment

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

@jhass What is the representation of the value called after it is formatted by %a or %A. I got these results while trying out.

io = MemoryIO.new
io.printf("Hello %a", 4)
p io.to_s # => "Hello 0x1p+2"

What is this form 0x1p+2 called?

Copy link
Member

Choose a reason for hiding this comment

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

I strongly suggest to base the docs on this: http://ruby-doc.org/core-2.2.0/Kernel.html#method-i-sprintf

Copy link
Member

Choose a reason for hiding this comment

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

There are some differences, but Ruby docs on this are pretty good

Copy link
Author

Choose a reason for hiding this comment

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

Cool. I shall try to follow the Ruby docs.

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.

#printf docs missing
3 participants