Frage

Let's use this class definition as an example:

class Person
  def fname
    @fname
  end
  def fname=(fname)
    @fname = fname
  end
  def lname
    @lname
  end
  def lname=(lname)
    @lname = lname
  end
end

Just trying to connect the dots between Ruby and C++ syntax for example.

War es hilfreich?

Lösung

Yes, @foo-ish variables are instance variables.

Note the above can be shortened to:

class Person
  attr_accessor :fname, :lname
end
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top