ruby 模块 respond_to】的更多相关文章

def hi puts 'hi friend' end module Amodule def self.hello puts 'hello friend' end end def rsp(txt) puts "回应 #{txt} = #{self.respond_to?(txt, true)}" end def arsp(txt) puts "回应 #{txt} = #{Amodule.respond_to?(txt, true)}" end rsp('hi') #…
Ruby 模块(Module) 模块(Module)是一种把方法.类和常量组合在一起的方式.模块(Module)为您提供了两大好处. 模块提供了一个命名空间和避免名字冲突. 模块实现了 mixin 装置. 模块(Module)定义了一个命名空间,相当于一个沙箱,在里边您的方法和常量不会与其他地方的方法常量冲突. 语法 module Identifier statement1 statement2 ........... end 模块常量命名与类常量命名类似,以大写字母开头.方法定义看起来也相似:…
Ruby模块(module) 2013-04-03 16:47:09|  分类: Ruby |  标签:ruby  require  load  extend  include  |字号 订阅     Ruby 和 Java 一样支持单继承,也正如 Java 引入 interface 来解决多继承的两难问题一样,Ruby 也提供了单继承和多继承的妥协机制:即模块. 模块的定义和类比较相似,使用module关键字.但模块不能被实例化,也不能被子类化,模块是独立的,且一个模块对像是Module类的一…
http://ruby-metaprogramming.rubylearning.com/html/ruby_metaprogramming_2.html http://galeki.is-programmer.com/posts/183.html 1.3.2 send  send( ) is an instance method of the Object class. The first argument to send( ) is the message that you're sendi…
Ruby是单一继承,一个类只能有一个直接的母类 Mix-in 模式来处理复合需求 多重包含: 由下往上回溯,重复的只看最上方的      换句话说,程序由上往下执行,由具体到抽象,第二次发现同一个模块就无视     类定义  class class-name   ...  end 注:  实例变量开头@       类变量开头@@       包含模块用 include module-name       attr_reader, attr_writer, attr_accessor 查看是否包…
//gem install redis时会遇到如下的error: //借助rvm来update ruby版本…
module My NA="China" def My.set_name(name) @name=name end def My.get_name return @name end def My.set_age(age) @age=age end end My.set_name("wanwgenfei") p My.get_name p My::NA module Your Na="AC" attr:name def Your.set_name(…
当一个类拥有可以从多个父类继承的特点,类应该显示多重继承. Ruby没有直接支持多继承,但Ruby模块有另一个精彩使用.他们几乎消除多重继承的需要,提供了一个工厂,称为混入. 混合类型给一个精彩的控制方式增加功能类.在代码中混合类,使用它的代码能进行交互. 语法: module A def a1 end def a2 end end modlue B def b1 end def b2 end end class Sample include A include B def s1 end end…
1.try 永远不会抛出异常 在 没有的时候 返回 nil province_id = Province.find_by_name(prov).try(:id) 2.find(:first, :condotions) 方法 不言而与 mobile_info = MobileInfo.find(:first, :conditions => ["mobile_num = ? ", mobile_num.to_i]) 3.find(:all, :select, :conditions)…
使用Ruby连接数据库的过程还真的是坎坷,于是写点文字记录一下. 简介 Ruby简介 RubyGems简介 包管理之道 比较著名的包管理举例 细说gem 常用的命令 准备 驱动下载 dbi mysql mysql2 MySQL的CC连接器 测试环境 代码测试 连接数据库 CRUD Select Delete Update Insert 仿PreparedStatement 假冒伪劣版 假冒伪劣进阶版 处理结果集 表结构 结果集遍历 总结 简介 Ruby简介 Ruby是一种纯粹的面向对象编程语言.…