首页 > 学院 > 开发设计 > 正文

module

2019-11-06 07:13:00
字体:
来源:转载
供稿:网友
module Tool  #这个方法无法直接运行  def show_tip    "this is the tip"  end  #这个方法可以通过Tool.say来运行  def self.say    puts "self.say"  endend

Tool.say

#############在类中调用############

require './Apple5.rb'
新建Apple4.rb,下面是Apple4.rb的内容class Student  include ToolendStudent.new.show_tipclass Teacher  include ToolendTeacher.new.show_tip

运行结果

vagrant@vagrant-Ubuntu-trusty-64:/vagrant/test_PRoject$ ruby Apple4.rbthis is the tipthis is the tip


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表