20/20 Please anybody can say what is wrong with my code?


#1



class Message
    @@messages_sent=0
    def initialize(from,to)
        @from=from
        @to=to
        @@messages_sent +=1
    end
end

my_message=Message.new(@from,@to)

class Email< Message
def initialize(from,to)
        super
    end
end

the console is showing "superclass mismatch for class Email"`


#2

The variables in your arguments are not defined in this scope. Use two strings.

 Message.new("Me", "You")

#3

Ok,thanks,but after i changed my code, the message of error changed to :
"uninitialized constant Context::Messsage"

class Message
@@messages_sent=0
def initialize(from,to)
@from=from
@to=to
@@messages_sent +=1
end
end

my_message=Message.new("x","y")

class Email< Messsage
def initialize(from,to)
super
end
end

i still do not understand what is wrong with my code, i have not declared Message as one constant in any place.

ps:Sorry for my bad english, english in not my native language.


#4

This line occurs before the Email class definition. Move it to the bottom and try again.


#5

Thank you very much, after trying from this way who you say the code finally worked.


#6

Looked at your solution and even though it works it doesn't make since. My code is exactly the same and I have no issues. Take a look so we can find the real issue.

class Message
    @@messages_sent = 0
    def initialize(from,to)
        @from = from
        @to = to
        @@messages_sent += 1
    end
end

my_message = Message.new("test","test2")

class Email<Message
    def initialize(from, to)
        super
    end
end

#7

It's very strange,if your code Works normally, why the mine only Works after the alterations?,May be some problem in the CodeAcademy plataform?


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.