From: Wyatt Greene Date: 2008-01-28T14:20:02+09:00 Subject: Re: Module Global Hash On Jan 28, 12:06 am, Ryan Lewis wrote: > #!/usr/bin/env ruby > module Users > class User < Struct.new(:screenname, :password, :dob, :join_date, > :age) > def initialize(sn, pw, dob) > self.screenname = sn > self.password = pw > self.dob = Time.parse(dob) > self.join_date = Time.now > self.age = Time.now.year - Time.parse(dob).year > end > end > ######################################### > user_hash = {} > > def new(sn, pw, dob) > Users::user_hash[sn] = User.new(sn, pw, dob) > end > ######################################### > module_function :new > end > > I'm trying to make it so when I call: > Users::new("screenname", "pass", "1/15/91") > > it adds a new instance of the User class into user_hash, but when I > execute the above code in IRB I get a NoMethodError for user_hash for > the Users:module > > I've also tried putting both a @ and @@ infront of user_hash but irb > comes up with the same error. > -- > Posted viahttp://www.ruby-forum.com/. Remember that in Ruby, everything is an object and objects communicate by passing messages (calling methods). So you can't get to variables of an object (such as user_hash). You can only call methods that an object responds to.