e7.3-1.rb

来自「ruby语言教程,Ruby是一种动态语言」· RB 代码 · 共 23 行

RB
23
字号
#E7.3-1.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 Person 
  def talk
    puts "I'm talking."    
  end  
end

class Student < Person
  include Me
end

aStudent=Student.new
aStudent.talk
puts aStudent.sqrt(20.7,3.3)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?