1

Looking for a way to populate instance variables in a new object. For instance:

p = Company.new(:company_name => "Alpha Company", :company_address => "123 Yonge Street", :company_city => "Toronto", :company_postal_code => "M4T 1A1", :company_phone => "416-456-7890", :company_url => "anybiz.biz")

Named parameters report that that statement has wrong number of arguments(given 1, expected 0). I just want to create an object and populate it as easily as possible. There has to be a way.

Also, keep in mind that I'm trying to approach this systematically as I'm writing some methods to abstract adoption of values outside of the object (in a hash) to the ivars inside instances.

Any insight appreciated. Cheers

Rich_F
  • 1,830
  • 3
  • 24
  • 45
  • 2
    How does your initialize method look like? – Kumar Akarsh Oct 10 '16 at 00:55
  • the easiest way to create an object and populate it freely would be to use a hash. You can also use openstruct if you want a more javascript-like interface (dot-methods for attributes) – max pleaner Oct 10 '16 at 03:05
  • Yes, it is a duplicate. I was assuming there was some kind of auto-sensing of a hash or parameters thrown at an instance to overwrite ivars. – Rich_F Oct 10 '16 at 03:31
  • I was about to post an answer, see here for something which may [help](http://stackoverflow.com/a/35735265/5101493) – Sagar Pandya Oct 10 '16 at 03:53

0 Answers0