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

Pretty print object as executable code #426

Open
forthrin opened this issue Jul 25, 2023 · 0 comments
Open

Pretty print object as executable code #426

forthrin opened this issue Jul 25, 2023 · 0 comments

Comments

@forthrin
Copy link

forthrin commented Jul 25, 2023

If there a way to make this (or another) gem print objects on a form that:

  1. generates the same object (ie. can be preceded by foo = and run as code)
  2. passes Rubocop validation
  3. has smart options for things like
  • contracting short arrays on a single line
  • replacing (recent) timestamps with Time.now
  • replace JSON with {...}.to_json
  • replace query URLs with something like "https://domain/path/?#{URI.encode_www_form({a: 1, b: 2, ...})"
one = [
  false, 42, %w[forty two],
  { now: Time.now, class: Time, distance: 4.2e+43 }
]
ap(one)
[
  false, 42, %w[forty two],
  { now: Time.now, class: Time, distance: 4.2e+43 }
]

For me personally it doesn't need support for classes, methods, etc. as I assume that's the 80% of the Pareto principle.

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

No branches or pull requests

1 participant