How do I iitialze this class?

P

Pepe Sanchez

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?
 
S

Stefano Crocco

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?

Try this:

class Ticket

attr_reader :event

def initialize msg
@event = msg
end

end

Stefano
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,897
Members
47,439
Latest member
shasuze

Latest Threads

Top