ITPUB??ì3
ITPUB论坛 » 动态语言 » Ruby的inspect方法究竟是啥?

新一届的微软MVP评选已经开始,欢迎各位推荐!

标题: Ruby的inspect方法究竟是啥?
离线 huangyuesong
一般会员



精华贴数 0
个人空间 0
技术积分 384 (5064)
社区积分 0 (110956)
注册日期 2004-4-5
论坛徽章:0
      
      

发表于 2007-6-7 11:38 
Ruby的inspect方法究竟是啥?

class VU
        include Comparable
        attr :volume
       
        def initialize(volume)
                @volume = volume
        end
        def inspect
                '#' * @volume
        end
       
        def <=>(other)
                self.volume <=> other.volume
        end
        def succ
                raise(IndexError, "Volume too big" if @volume >= 9
                VU.new(@volume.succ)
        end
end

为什么区间的每个值变成###....组成了呢?


__________________
>> 假作真时真亦假,无为有处有还无
只看该作者    顶部
离线 wccq
初级会员



精华贴数 0
个人空间 0
技术积分 6 (131113)
社区积分 0 (1560061)
注册日期 2007-9-17
论坛徽章:0
      
      

发表于 2007-9-20 22:06 
inspect 迭代对象很好用。


只看该作者    顶部
 
    

相关内容


CopyRight 1999-2006 itpub.net All Right Reserved.
北京皓辰广域网络信息技术有限公司. 版权所有
E-mail:Webmaster@itpub.net
京ICP证:010037号 联系我们 法律顾问