Ruby - Class method that returns an instance & modifies that instance -


looking set class method can return array of instances. i'm running trouble point try modify instances' variables nomethoderror: undefined method 'name=' #<class:0x007fe65c8560c0>.

class user   attr_accessor :name    def self.sample_users     megan = self.class.new     megan.name = "megan"      jack = self.class.new     jack.name = "jack"      [megan, jack]   end end 

i feel should possible in ruby. guidance?

use new instead of self.class.new

class user   attr_accessor :name    def self.sample_users     megan = new     megan.name = "megan"      jack = new     jack.name = "jack"      [megan, jack]   end end 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -