2 Replies - 1095 Views - Last Post: 08 March 2012 - 12:28 PM Rate Topic: -----

#1 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Grep the output of #inspect on objects you've forgetten aspects of

Posted 08 March 2012 - 11:07 AM

Hey, so I'm working with a couple objects in rails and I've forgotten the exact spelling and format of an attribute. I know it has the word vendor in it. Typically, I'm programming with the rails console up, and I would just type

1.9.2-p180 :022 > Product.inspect
 => "Product(id: integer, P_Id: integer, Pc: integer, Sku: integer, Subcat: integer, Description: text, UnitOfMeasure: string, Vendor: integer, VendorSku: string, Manufacturer: integer, ManufacturerSku: string, Upc: string, AverageCost: decimal, CurrentCost: decimal, PriceLevel1: decimal, PriceLevel2: decimal, PriceLevel3: decimal, PriceLevel4: decimal, PriceLevel5: decimal, PriceLevel6: decimal, PriceLevel7: decimal, PriceLevel8: decimal, PriceLevel9: decimal, PriceLevel10: decimal, LeadIn: integer, MinOrderQty: integer, MinStockLvl: integer, MaxStockLvl: integer, OnHand: integer, created_at: datetime, updated_at: datetime)"



But then I have to really strain my eyes and look for something with the word 'vendor' in it to make sure it's not vendor_sku or VendorSku or vendorSku.

So is there a quick cool way to grep through the list, or alphabetize it and give them individual lines so it's more fun?

Is This A Good Question/Topic? 0
  • +

Replies To: Grep the output of #inspect on objects you've forgetten aspects of

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2086
  • View blog
  • Posts: 3,173
  • Joined: 21-June 11

Re: Grep the output of #inspect on objects you've forgetten aspects of

Posted 08 March 2012 - 12:23 PM

Product.inspect.split(",").grep(/vendor/i) would work. Or a bit cleaner, but without using inspect:

Product.column_names.grep(/vendor/i)

Was This Post Helpful? 2
  • +
  • -

#3 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: Grep the output of #inspect on objects you've forgetten aspects of

Posted 08 March 2012 - 12:28 PM

Thanks, that's perfect!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1