getter and setter

class TestSetterGetter
  attr_accessor :something

  def any_method
    self.something = "abc"
    #setter inside class, instead of @something
    puts something
    #getter inside class
  end
end

test = TestSetterGetter.new
test.something = "test"
# setter
puts test.something
# getter
#=> "test"
test.any_method
#=> "abc"

Reference

results matching ""

    No results matching ""