2013年11月22日

ruby 使用grep和=~的返回值

摘要: result="str".grep(/re/):如果没有匹配成功则,result.to_s为“”,所以不应使用if "str".grep()来判断是否有成功的匹配,即时没有成功的匹配"str".grep()也是非nil非false的。可以使用=~进行判断,如果没有匹配成功的话"str" =~ /re/会返回nil。 阅读全文

posted @ 2013-11-22 23:16 优雅的码农 阅读(774) 评论(0) 推荐(0)

Instance Variables

摘要: Instance variables begin with an at sign (@) and can be referenced only within class methods. They differ from local variables in that they don't exist within any particular scope. Instead, a similar variable table is stored for each instance of a class. Instance variables live within a class in 阅读全文

posted @ 2013-11-22 22:53 优雅的码农 阅读(514) 评论(0) 推荐(0)

导航