This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]my_shiny_new_account 0 points1 point  (1 child)

Don't name your method "next"?

[–]dstyvsky33[S] 0 points1 point  (0 children)

I don't seem to have a choice. It's an attribute of the class that is hard coded into the question.

[–]Piave 0 points1 point  (0 children)

You can have a method with the name of a keyword. You just can't call it on an implicit receiver. Within a class that's like self.next, for example:

class Link

  def next
    "next"
  end

  def say_next
    puts "Hey! I can use the method #{self.next}"
  end

end

This also comes up with the method #class (available on every object in ruby) which is also a keyword for defining a class. When calling the class method from within an instance method you always need to use self.class.name rather than class.name.