From: Brian Candler Date: 2010-08-01T20:30:47+09:00 Subject: Re: Beginner help needed: use a class def to create new instance Steve P. wrote: > class Character > attr_reader :chname, :chnick, :chquote > def initialize(chname,chnick) > @chname=chname > @chnick=chnick > @chquote=String.new > end > def addquote(quote) > @chquote=quote if quote.length > 10 > end > def promptedinput > print "Char name: ";chname=gets.chomp > print "Char Nick: ";chnick=gets.chomp > print "Char Quote: ";chquote=gets.chomp > # Need help here! > # What code goes here to add Character class instance? > # class instance name should be newchar > end > end I think you want a class method, not an instance method, since you're creating a new object which doesn't have any relation to any existing object. class Character def initialize(chname,chnick,chquote="") @chname=chname @chnick=chnick @chquote=chquote end def self.promptedinput print "Char name: ";chname=gets.chomp print "Char Nick: ";chnick=gets.chomp print "Char Quote: ";chquote=gets.chomp new(chnam,chnick,chquote) end end newchar = Character.promptedinput puts newchar.inspect Note that I modified your initialize method to accept chquote as an optional third argument. If you don't want to do that, then:: def self.promptedinput print "Char name: ";chname=gets.chomp print "Char Nick: ";chnick=gets.chomp print "Char Quote: ";chquote=gets.chomp result = new(chname,chnick) result.chquote = chquote result end -- Posted via http://www.ruby-forum.com/.