e7.3-2.rb
来自「ruby语言教程,Ruby是一种动态语言」· RB 代码 · 共 16 行
RB
16 行
#E7.3-2.rb
module Me
def sqrt(num, rx=1, e=1e-10)
num*=1.0
(num - rx*rx).abs <e ? rx : sqrt(num, (num/rx + rx)/2, e)
end
end
class Student
end
aStudent=Student.new
aStudent.extend(Me)
puts aStudent.sqrt(93.1, 25)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?