Lv1.梦旅人
您需要 登录 才可以下载或查看,没有帐号?注册会员
module ABC def test p "Test" endend
module ABC def test p "Test" end end
使用道具 举报
RyanBern 发表于 2015-4-12 00:02 可以,没有什么本质区别。 如果A类已经糅合了ABC模块,那么使用A类也可以调用ABC模块的方法。 module ABC ...
脚本.zip
2015-4-12 00:15 上传
点击文件名下载附件
20.46 KB, 下载次数: 58
Lv4.逐梦者 (版主)
wangzh9173 发表于 2015-4-11 23:57 谢谢版主大大,继续以上面这个为例,那能不能在A类中调用ABC Module中的方法呢 ...
module ABC def test p "Test" end def self.test p "Module Function : Test" endend a = A.newa.test # => "Test" class B def test_b ABC.test endend b = B.newb.test_b # => "Module Function : Test"
module ABC def test p "Test" end def self.test p "Module Function : Test" end end a = A.new a.test # => "Test" class B def test_b ABC.test end end b = B.new b.test_b # => "Module Function : Test"
RyanBern 发表于 2015-4-11 23:47 这样写的话要把此module糅合到其他类中才能使用这个类的对象调用。 class A include ABC
class A include ABCenda = A.newa.test # => "Test"
class A include ABC end a = A.new a.test # => "Test"
module ABC def self.test p "Test" endend ABC.test # => "Test"
module ABC def self.test p "Test" end end ABC.test # => "Test"
本版积分规则 发表回复
献给最先抵达这片土地的你。参加预注册的用户即可获得。
这里的今天,有我过往努力的见证~
写评论什么的超开心的![为2017年寒假活动『剧情大挑战Ⅱ』撰写有效评测3篇及以上]
折叠内容标题(非必须)
折叠内容
站长信箱:fux2@moe9th.com|手机版|小黑屋|无图版|Project1游戏制作
GMT+8, 2025-7-29 22:33
Powered by Discuz! X3.1
© 2001-2013 Comsenz Inc.