When you use an access modifier, all the methods that follow are defined with that access, until you use a different access modifier. : Access level « Class « Ruby






When you use an access modifier, all the methods that follow are defined with that access, until you use a different access modifier.


class Animal
  def initialize(color)
    @color = color
  end

  public
  def get_color
    return @color
  end

  private
  def get_feet
    return "four"
  end

  def get_sound
    return "Bark"
  end
end

 








Related examples in the same category

1.Ruby gives you three levels of access:
2.A class with public, protected and private accessors
3.label methods: private or protected will have the indicated visibility until changed or until the definition ends.