视频中代码可运行吗?
class Apple
def initialize
# instance variable,
@color
end
# getter
def color
return @color
end
# setter
def color = color
@color = color
end
# private 下面是私有方法
private
def i_am_private
end
end
red_apple = Apple.new
red_apple.color = 'red'
puts "red_apple.color: #{red_apple.color}"
#下面是报错
test.rb:14: syntax error, unexpected '=', expecting ';' or '\n'
def color = color
^
test.rb:22: syntax error, unexpected keyword_end, expecting end-of-input