报名
传说中的胸器!
必须去
最近访问特别慢,比以前
@neverlandxy_naix @dddd1919 多谢!
搞清楚了,在 Blog 中初始化的
...
def new_post(*args)
post_source.call(*args).tap do |p|
p.blog = self
end
end
def post_source
@post_source ||= Post.public_method(:new)
end
...
end
还有个疑问,上面的 blog.add_entry(self) 没有@符号? 是不是这里使用的不是实例变量,而是一个方法?
分享下一本免费书《Clever Algorithms》,书中涉及了很多智能算法,例子用 ruby 实现,http://www.cleveralgorithms.com/nature-inspired/index.html, 不过,个人觉得机器学习还是用 python 和 R 比较方便。
积累中的人飘过...
@Peter 已附上 @kewin 使用 XMind http://www.xmind.net/ @subway 是的,我自己也不太满意,无奈暂时还没有更好的灵感。 源文件已附上,求改进美化
@chenge 3 我觉得是迭代字符串,不知这个描述是否准确? 5 我也是在查找块资料是发现的。这里再参考别人的代码对比下
# 1.9之前
current = "2012"
1.upto(10) do |i|
current = i
succ = current + 1
print "#{current}, #{succ}"
end
print current #=> 10
# 1.9以后
current = "2012"
1.upto(10) do |i ;current|
current = i
succ = current + 1
print "#{current}, #{succ}"
end
puts current #=> 2012
Block variable scope in Ruby is pretty intuitive – especially for those of us who are familiar with similar functionality in JavaScript. The newer block-local functionality in Ruby 1.9 is nice, but it’s only going to be useful in some niche scenarios. I would rather use more descriptive variable names to avoid overriding variables by accident. 原文http://www.jacopretorius.net/2012/01/block-variable-scope-in-ruby.html
@chenge 谢谢,我也觉得块是最酷的特性之一,另外,新补充了块的使用,欢迎指点
@sjzg001 本章重点不是 ruby 中方法的一般特性和使用,主要讲有关代码重构的技术。通过 ruby 的特性消除重复代码,使代码简洁,遵循 DRY(Don‘t repeat yourself) 原则,提高可维护性。
@sjzg001 自觉对本章内容理解把握的不够透彻,自身复制粘贴了部分内容,可能没把重点和思路表达清楚。不知哪里困扰在何处,哪里不懂?请反馈以求共同进步
@sunday35034 thx,已修正。
@alixiaomiao 多谢指正,笔误 method_mission 已修改,模块不存在实例,但其中定义的方法也叫实例方法吧
是的,鱼骨头,只是这条鱼太胖了
@hntee 我用的是 xmind
mark,谢分享
@lazy 方式是很多,都要靠时间积累才有明显成效。现在有空还去跑跑步,其他的都持续不了多久,贵在坚持!是不是程序员都有懒惰的天性
看到过一个叫 nlpir 的东东,用于中文分词的
不久前在 hacker news 上看到原文,这么快就看到译文了,good job!
Struct , OpenStruct, Hash 各自适用场合 Use Struct if 1.you need a data container and fields are fixed and known beforehand (i.e. at time of writing of the code), 2.you need a structured Hash key, 3.you want to quickly define a class with a few fields, 4.you need to detect errors caused by misspelled field names.
Use OpenStruct if 1.the number of fields is fixed at runtime but varies frequently during development time (this is often the case for objects that should hold the result of command line option parsing), 2.you need a mock or a want to quickly have objects at hand which can be filled via usual attribute setters and getters. You might want to replaced with a proper class (or Struct) later — with explicit attribute declarations via attr_accessor and relatives.
Use Hash if 1.the number of fields is unknown at coding time, 2.there is a potentially unlimited number of fields (e.g. when reading key values from a file as is often the case for script based text processing). 原文http://blog.rubybestpractices.com/posts/rklemme/017-Struct.html
good job, 多谢分享! c 中的 Struct 比较简单,不支持方法,Struct 更像是 C++ 中的 struct