Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@arches
Last active December 25, 2015 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arches/6907695 to your computer and use it in GitHub Desktop.
Save arches/6907695 to your computer and use it in GitHub Desktop.
table_print for pure ruby objects
> my_array = [{server: "localhost", ip: "192.168.0.1"}, {server: "google dns", ip: "8.8.8.8"}]
> tp my_array
SERVER | IP
-----------|------------
localhost | 192.168.0.1
google dns | 8.8.8.8
# or with objects
> class ServerInfo
> attr_accessor :server, :ip
> def initialize(server, ip)
> self.server = server
> self.ip = ip
> end
> end
> my_array = [ServerInfo.new("localhost", "192.168.0.1"), ServerInfo.new("google dns", "8.8.8.8")]
> tp my_array
SERVER | IP
-----------|------------
localhost | 192.168.0.1
google dns | 8.8.8.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment