虽然这里是 Ruby 论坛,但是我不建议大家黑 Python,不如联合 Python 的人大家一起黑一下比如 PHP 什么的。。。吼吼吼
作为组织了 5 次 RubyConfChina,而且还是 PyCon 上海前两届的主持人,我欢迎你!
~ $ irb
>> class Song
>> def initialize(name,artist,duration)
>> @name =name
>> @artist =artist
>> @duration = duration
>> end
>>
?> def to_s
>> "Song: #@name #@artist(#duration)"
>> end
>>
?> end
=> nil
>> class KaraokSong < Song
>> def initialize(name,artist,duration,lyrics)
>> super(name,artist,duration)
>> @lyrics=lyrics
>> end
>>
?> def to_s
>> super+ "[#@lyrics]"
>> end
>> end
=> nil
>> song = KaraokSong.new("adsf","dsaf",34234,"234")
=> #<KaraokSong:0x007fc91185b290 @name="adsf", @artist="dsaf", @duration=34234, @lyrics="234">
>> song.to_s
=> "Song: adsf dsaf(#duration)[234]"
去查一下 Apache 的 error logs,任何 500 错误都有原因,查一下日志大概就能判断出来。
#1 楼 @HungYuHei 真是手快有,手慢无啊!
你查过文档吗?还是不知道怎么查文档?
http://api.rubyonrails.org/classes/ActiveRecord/Calculations.html#method-i-sum 可以看到, sum
就是干这个的。
你可以用 rails new project_name -d postgresql
生成一个 dumb 的项目自己对比一下。
class 的初始化方法是 initialize
, 好好检查一下你的拼写。
第一次知道这个用法,毫无疑问用 throw / catch 跳出嵌套循环干净利索,不过从可读性和表达性上看,这个用法在 Rubyist 中可能很难流行吧。
引用的文章中的评论也有亮点,特别是这篇 Dont Use Exceptions For Flow Control 中还特别提到了 Ruby 的这种用法:
The RubyLanguage has separate mechanisms for reporting errors and UnwindingTheStack as flow control. The begin...rescue and raise statements are used for reporting and handling methods. The throw...catch statements are used for unwinding deeply nested calls.
#32 楼 @wangping Bug 请发到 Github 上:https://github.com/ruby-china/ruby-china/issues?state=open
尽快升级到 Ruby 2.0.0 吧。
有种想要加精的冲动,如果 B 大 能来 Teahour 做客的话.....
#2 楼 @u1378130755 问题是你的描述没有上下文,其他人是看不懂的呀。
你为什么不贴代码?
非常赞!不过好像不需要 JLRubyChina-iPhone-Release 这个项目,完全可以用 releases 功能打包嘛。
《ruby 元编程》有奖试读活动,出版社去 CU 发帖干嘛?为嘛不来这里啊?
如果能先睹为快的话... 是提不出意见的呀!