ruby入门_模块
2012-02-29 14:39
225 查看
模块(module)和类同一级
和类类似,但是不能实例化
可以被类包含
self可以指定模块方法
输出
foo2. module method
foo1. common method
foo3.
和类类似,但是不能实例化
可以被类包含
self可以指定模块方法
module DemoModel def foo1 # common method puts "foo1. common method" end def self.foo2 # module method puts "foo2. module method" end end # here is error # DemoModel.foo1 DemoModel.foo2 # ------------------------------------- # class with module class DemoClass include DemoModel end demo = DemoClass.new demo.foo1 # ------------------------------------- # module with class module DemoModel1 class DemoClass1 def foo3 puts "foo3." end end end demo1 = DemoModel1::DemoClass1.new demo1.foo3
输出
foo2. module method
foo1. common method
foo3.
相关文章推荐
- Ruby快速入门(四):类和模块
- Ruby快速入门(四):类和模块
- 「诱人的Ruby」入门篇调查报告总结
- Ruby on Rails bundle install 缺失模块安装
- Webpack 入门指南 - 2.模块
- Ruby on Rails 入门之:(3) Ruby中的多种字符串表示方法
- python-模块入门
- selenium从入门到应用 - 5,页面对象设计模式下的页面模块
- Ruby on Rails 入门之:(8) Ruby中条件语句
- 2.Nodejs入门-----模块
- [转]几个python 入门程序--例2( 如何将多个模块打包成一个模块)
- python入门(二十一):xml模块
- ruby入门_HelloWorld
- 利用Radrails开发Ruby on Rails程序入门指南
- NodeJS的模块写法入门(实例代码)
- ruby on rails入门系列--一个简单的HelloWorld程序
- Hadoop入门实践之构造模块
- XOOPS模块开发快速入门中文翻译(六)
- PP模块快速入门之功能简介
- ruby入门_特殊类