zhyiwww
用平实的笔,记录编程路上的点点滴滴………
posts - 536,comments - 394,trackbacks - 0
我的代码如下:
class Song

    def initialize(name)
        @name = name
    end

    def tell
        puts @name
    end

end

class ZhouSong < Song

    def initialize(name,artist)
        super(name)
        @artist = artist
    end

    def tell
        super
        puts @artist
    end

    def name=(newName)
        @name = newName
    end
   
    attr_writer :artist

end


s = Song.new("song")
s.tell


zs = ZhouSong.new("zhousong","zhoujielun")
zs.tell
zs.name = "name : new zhou song"
zs.tell

zs.artist = "artist : zhoujielun "
zs.tell

我希望删除所有的空行,可以用sed来实现
文件名是a.rb
more a.rb | sed "/^\s*$/d"
结果如下:
class Song
        def initialize(name)
                @name = name
        end
        def tell
                puts @name
        end
end
class ZhouSong < Song
        def initialize(name,artist)
                super(name)
                @artist = artist
        end
        def tell
                super
                puts @artist
        end
        def name=(newName)
                @name = newName
        end
        attr_writer :artist
end
s = Song.new("song")
s.tell
zs = ZhouSong.new("zhousong","zhoujielun")
zs.tell
zs.name = "name : new zhou song"
zs.tell
zs.artist = "artist : zhoujielun "
zs.tell

如果您想直接修改文件,那么可以用
sed -i "/^\s*$/d" a.rb



|----------------------------------------------------------------------------------------|
                           版权声明  版权所有 @zhyiwww
            引用请注明来源 http://www.blogjava.net/zhyiwww   
|----------------------------------------------------------------------------------------|
posted on 2008-12-12 16:34 zhyiwww 阅读(4587) 评论(0)  编辑  收藏 所属分类: linux

只有注册用户登录后才能发表评论。


网站导航: