![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Ruby&Rails
iteye_8450
这个作者很懒,什么都没留下…
展开
-
Ruby方法
Ruby方法1、参数可以有默认值,对java的多态而言可以省去很多代码def method(arg1='hello',arg2='world')end2、可以一次性传递任意多个参数,以*开头,只能放在方法定义的最后一个参数位置def method(arg1='hello',*arg2)endarg2是一个Array的参数数组3、块和Proc对象的关联。当方法接受参数...2006-12-08 08:59:24 · 74 阅读 · 0 评论 -
Ruby遍历目录
编辑们在开发过程中收集了很多的文本内容,内容按类别存放在多级目录中。需要将收集的内容导入数据库,应此需要遍历目录。用java实现了该功能。 学了ruby后,拿这个需求练手了 :D 代码如下:require 'pathname'def walk_dir(path_str) path = Pathname.new(path_str) path.chi...2006-12-08 09:34:00 · 161 阅读 · 0 评论 -
Ruby Class里的变量
Class variables:用于描述属于class 的 states,而非属于某个object的states1.表现形式 @@var2.属于特定的class而不是object3.在使用前,必须初始化class Song@@plays = 0def initialize(name, artist, duration)@name= n...2006-12-16 22:48:58 · 112 阅读 · 0 评论 -
ruby里的require、load与include
require、load类似java中的import,引入别的文件中定义的类include用于实现mixin,引入module。[code]# Mixins.rbmodule D def initialize(name) @name =name end def to_s @name endendmodule Debug inclu...2006-12-17 10:43:27 · 72 阅读 · 0 评论 -
ruby的继承与mixin
继承与mixin的最主要的区别在于你可以mixin超过一个的module,而类只能从一个类中继承。2006-12-17 11:13:50 · 171 阅读 · 0 评论