How do I iitialze this class?

When I try to initialize this class

class Ticket
def event
$event
end
end

ticket = Ticket.new(“Can’t really be specified yet…”)
puts ticket.event

I get an error message:
undefined method `event’ for nil:NilClass

Why?

On Saturday 23 August 2008, Pepe S. wrote:

I get an error message:
undefined method `event’ for nil:NilClass

Why?

Try this:

class Ticket

attr_reader :event

def initialize msg
@event = msg
end

end

Stefano

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs