From: Corey Jewett Date: 2007-08-24T07:46:01+09:00 Subject: Re: ruby shell? On Aug 23, 2007, at 3:01 PM, Tomas Pospisek's Mailing Lists wrote: > How about being able to do these things with a Ruby DSL? Like: > > for lines in { line.split.map ... } > /tmp/ > passwd.changed > h = Hash.new < `ls #{my_dir}`.special_sort | `tee /tmp/temp_copy` > > That would be nice. The shell would need to be interactive and non- > interactive... I haven't looked at any of the projects already out there, just piqued my interest enough to generate this: corey@leviathan ~> irb >> class File >> class << self >> alias :[] new >> end >> ?> def lines &block >> arr = self.readlines >> arr.collect! {|line| yield line} if block_given? >> arr >> end >> end => nil >> ?> module Kernel >> define_method :> do |file| ?> File.open(file, 'w') << ?> case ?> when self.class.respond_to?(:join): self.join('\n') >> else ?> self.to_s >> end >> end >> end => # >> ?> ?> File["/etc/passwd"].lines {|line| line =~ /^appserver/ ? nil : line }.compact > "/tmp/passwd.changed" => # >> quit corey@leviathan ~> diff /etc/passwd /tmp/passwd.changed 27d26 < appserver:*:79:79:Application Server:/var/empty:/usr/bin/false