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
# NB: This method utilizes 'pbcopy' which is only available on MacOS. | |
# | |
# I often find myself in the IRB or Pry console needing to both format a Ruby Hash and copy it to the clipboard. | |
# Here is a covenient method that can accomplish both of those tasks | |
# | |
# Consider this example: | |
# | |
# A co-worker asks you to text them the data from the most recent Post in your Rails app. | |
# | |
# You enter the rails console... |
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
# Below is a way to add a JSON module method #pretty_inline to receive a Ruby Hash and generate pretty JSON. | |
# This is similar to #pretty_generate only instead of adding indentation and newlines, this | |
# will produce an inline String. | |
# | |
# Under the hood, the method uses the JSON#generate method which accepts a 2nd optional argument of options. | |
# | |
# :object_nl (object newline) - normally a newline character (\n) but in this case, just a space. This will be | |
# inside curly braces and after commas | |
# | |
# :array_nl (array newline) - normally a newline character (\n) but in this case, just a space as well. This will |