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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -