Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <a href="https://github.com/cldwalker/hirb" rel="nofollow">Hirb</a> gem can be a good starting point for you. It's usually associated with IRB or Rail's console use, but there's nothing that says we can't subvert it for other uses.</p> <p>Normally it wants to wrap the table created with ASCII borders:</p> <pre> +--------------------+-----------------------------+------------+ | user_name | name | num_logins | +--------------------+-----------------------------+------------+ | email_1@yahoo.com | Beachwood | 2 | | email_2@yahoo.com | Beachwood | 2 | | email_3@yahoo.com | Beachwood | 2 | | email_4@yahoo.com | Beachwood | 2 | | email_55@yahoo.com | Community Internal Medicine | 6 | +--------------------+-----------------------------+------------+ </pre> <p>But, by applying a bit of <code>gsub</code> lovin' we can dress it up like you want:</p> <pre><code>values = [ [ 'user_name', 'name', 'num_logins' ], [ 'email_1@yahoo.com', 'Beachwood', '2' ], [ 'email_2@yahoo.com', 'Beachwood', '2' ], [ 'email_3@yahoo.com', 'Beachwood', '2' ], [ 'email_4@yahoo.com', 'Beachwood', '2' ], [ 'email_55@yahoo.com', 'Community Internal Medicine', '6' ], ] puts Hirb::Helpers::AutoTable.render( values, :headers =&gt; values.shift, :description =&gt; false ).gsub(/^[+-]+\n?/, '').gsub('|', ' ') </code></pre> <p>Which looks like:</p> <pre> user_name name num_logins email_1@yahoo.com Beachwood 2 email_2@yahoo.com Beachwood 2 email_3@yahoo.com Beachwood 2 email_4@yahoo.com Beachwood 2 email_55@yahoo.com Community Internal Medicine 6 </pre> <p>You might want to pop off the header line of the array before passing it to Hirb, or supply it from a separate array. Change the <code>:headers</code> option if so.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload