In Ruby, you can define getter methods for instance variables using the attr_reader
or attr_accessor
methods.
Here is an example of how to call a getter on an instance of a class in Ruby:
main.rb139 chars11 lines
In this example, the Person
class has a getter method for the name
instance variable defined using attr_reader
, which allows us to access the value of name
using the .name
method on an instance of Person
.
gistlibby LogSnag