Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > rails console output shows "\n" rather than putting in new line? isthere a way to change this?

Reply
Thread Tools

rails console output shows "\n" rather than putting in new line? isthere a way to change this?

 
 
Greg Hauptmann
Guest
Posts: n/a
 
      01-20-2009
[Note: parts of this message were removed to make it a legal post.]

Hi,
I note rails console shows "\n" rather than putting in new line? For
example:

?> Category.find(:first).to_yaml
=> "--- !ruby/object:Category \nattributes: \n updated_at: 2009-01-20
03:39:22\n tax_item_id: \n category_type_id: \"2\"\n title: Investment\n id:
\"1\"\n category_id: \n category_group_id: \"5\"\n created_at: 2009-01-20
03:39:22\n active: \"0\"\nattributes_cache: {}\n\n"


I note that if you "puts" the same thing from an Rspec test it formats fine
(with new lines)

Question: Is there a way to change this for the console?



--
Greg
http://blog.gregnet.org/

 
Reply With Quote
 
 
 
 
Rob Biedenharn
Guest
Posts: n/a
 
      01-20-2009
On Jan 20, 2009, at 3:00 PM, Greg Hauptmann wrote:
> Hi,
> I note rails console shows "\n" rather than putting in new line? For
> example:
>
> ?> Category.find(:first).to_yaml
> => "--- !ruby/object:Category \nattributes: \n updated_at: 2009-01-20
> 03:39:22\n tax_item_id: \n category_type_id: \"2\"\n title:
> Investment\n id:
> \"1\"\n category_id: \n category_group_id: \"5\"\n created_at:
> 2009-01-20
> 03:39:22\n active: \"0\"\nattributes_cache: {}\n\n"
>
>
> I note that if you "puts" the same thing from an Rspec test it
> formats fine
> (with new lines)
>
> Question: Is there a way to change this for the console?
> --
> Greg
> http://blog.gregnet.org/



either:
puts Category.find(:first).to_yaml
or since irb saves the last expression into the variable _ (yes, an
underscore):
puts _

-Rob

Rob Biedenharn http://agileconsultingllc.com
http://www.velocityreviews.com/forums/(E-Mail Removed)



 
Reply With Quote
 
 
 
 
Greg Hauptmann
Guest
Posts: n/a
 
      01-20-2009
[Note: parts of this message were removed to make it a legal post.]

excellent! thanks

On Wed, Jan 21, 2009 at 6:16 AM, Rob Biedenharn
<(E-Mail Removed)>wrote:

> On Jan 20, 2009, at 3:00 PM, Greg Hauptmann wrote:
>
>> Hi,
>> I note rails console shows "\n" rather than putting in new line? For
>> example:
>>
>> ?> Category.find(:first).to_yaml
>> => "--- !ruby/object:Category \nattributes: \n updated_at: 2009-01-20
>> 03:39:22\n tax_item_id: \n category_type_id: \"2\"\n title: Investment\n
>> id:
>> \"1\"\n category_id: \n category_group_id: \"5\"\n created_at: 2009-01-20
>> 03:39:22\n active: \"0\"\nattributes_cache: {}\n\n"
>>
>>
>> I note that if you "puts" the same thing from an Rspec test it formats
>> fine
>> (with new lines)
>>
>> Question: Is there a way to change this for the console?
>> --
>> Greg
>> http://blog.gregnet.org/
>>

>
>
> either:
> puts Category.find(:first).to_yaml
> or since irb saves the last expression into the variable _ (yes, an
> underscore):
> puts _
>
> -Rob
>
> Rob Biedenharn http://agileconsultingllc.com
> (E-Mail Removed)
>
>
>
>



--
Greg
http://blog.gregnet.org/

 
Reply With Quote
 
Ryan Davis
Guest
Posts: n/a
 
      01-20-2009

On Jan 20, 2009, at 12:00 , Greg Hauptmann wrote:

> Hi,
> I note rails console shows "\n" rather than putting in new line? For
> example:
>
> ?> Category.find(:first).to_yaml
> => "--- !ruby/object:Category \nattributes: \n updated_at: 2009-01-20
> 03:39:22\n tax_item_id: \n category_type_id: \"2\"\n title:
> Investment\n id:
> \"1\"\n category_id: \n category_group_id: \"5\"\n created_at:
> 2009-01-20
> 03:39:22\n active: \"0\"\nattributes_cache: {}\n\n"


irb inspects the result, either don't convert it to a string, or print
it.

?> Category.find(:first)

or

?> y Category.find(:first)

or as rob pointed out:

?> puts Category.find(:first).to_yaml

Usually I don't care about all the fields, so I'll do something like

?> Category.find(:first).title

and leave it at that.


 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      01-20-2009
> Question: Is there a way to change this for the console?

Don't rely on the console so much. Put puts in a unit test!
 
Reply With Quote
 
David A. Black
Guest
Posts: n/a
 
      01-20-2009
Hi --

On Wed, 21 Jan 2009, Phlip wrote:

>> Question: Is there a way to change this for the console?

>
> Don't rely on the console so much. Put puts in a unit test!


I rely heavily on the console, and also on unit tests. The two aren't
in conflict or competition; they're different tools. It's important to
know how irb (in Rails console form or otherwise) works, and why it
produces the output it does.


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to understand Ruby code? (noting various mixins/includes) Isthere a tool to assist here? Greg Hauptmann Ruby 4 12-08-2009 06:21 PM
isthere any tools that could help me check include dependency between c++ files? thinktwice C++ 10 07-01-2008 01:35 AM
Session var in page_load shows old value, buttonclick shows new . Whats wrong gce ASP .Net 0 05-07-2005 06:50 AM
Better way of getting parsed Python rather than an AST? Kenneth McDonald Python 1 10-10-2004 01:58 AM
Difference between putting code in constructor and putting code in static{} Saurabh Java 6 05-30-2004 02:44 PM



Advertisments