cast 的个人资料nonocast ! 真诚原是一种需要坚强不屈的...照片日志列表更多 ![]() | 帮助 |
|
|
6月15日 such a easy server1 require 'gserver'
2
3 class AirportServer < GServer
4 def initialize(host = 'localhost', port = '6699')
5 super(port, host)
6 end
7
8 def serve(session)
9 session.puts "got you"
10 session.puts(session.gets)
11 end
12 end
13
14 airport = AirportServer.new
15 airport.start
16 airport.join 6月10日 EBADF on rubytest.rb
print $_ while gets
然后在dos下:
ruby test.rb < data.txt
ok
test < data.txt
errno:EBADF
郁闷..
Hi,
At Sun, 19 Jan 2003 02:50:32 +0900, Shashank Date wrote: > > Also, is there a Windows equivalent of the '#!' line? > > There is a notion of "file associations" which is effectively the same > thing. In File Explorer if you select any file with .rb extension > 1. right click to get a pop-up > 2. then select "Open with" you get > 3. to "Choose" Program to "associate" the binary which will be used to open > this file type. Note that redirection doesn't work with associated programs. I don't know this is a feature of Windows or not. c:\home\nobu>assoc .rb=RubyScript .rb=RubyScript c:\home\nobu>ftype RubyScript=ruby.exe %1 %* RubyScript=ruby.exe %1 %* c:\home\nobu>type foo.rb #!/usr/bin/ruby print $_ while gets c:\home\nobu>ruby foo.rb foo.rb #!/usr/bin/ruby print $_ while gets c:\home\nobu>ruby foo.rb < foo.rb #!/usr/bin/ruby print $_ while gets c:\home\nobu>foo.rb foo.rb #!/usr/bin/ruby print $_ while gets c:\home\nobu>foo.rb < foo.rb C:/home/nobu/foo.rb:2:in `gets': Bad file descriptor (Errno::EBADF) from C:/home/nobu/foo.rb:2 -- Nobu Nakada update:
目前发现一种变通的办法
在查看了ruby lib的后发现
在ruby/bin中有很多.bat,.cmd
就启到了一个proxy的作用
在.cmd中写
@ruby "c:\rubycode\test.rb" %*
就ok了
这样就可以直接写
test < data.txt了
算是解决了一半的问题了 5月31日 EvaluatingRuby by martinFowlerIf you're reading this I assume you're aware of the fact that there's been a huge amount of fuss about the Ruby programming language, and in particular the Rails framework for developing web applications. Some see it as the future of programming, others as a dangerous diversion. I started with ruby several years ago. The pragmatics got me interested and it soon became my preferred scripting language. Over time it grew to handle much of the production of this website - in particular this bliki. I like the language a lot. There's a jump between my personal liking and whether it's something that should be used by our clients. We can evaluate its suitability for client projects based on its features - and this leads to many arguments about the pros and cons of dynamic typing, convention over configuration, processes versus threads, and the like. Such discussions are useful but I remain wary of them. Too many things are hard to judge that way - hence we spend so much of our time on client projects being slowed down by technology that sounded good on a golf course. My preference is to make this judgment based on experience - find people who have a track record for delivering in the mainstream environments and who have tried using Ruby. Some of this can be seen with public writers. Ruby has attracted many people who have good experience elsewhere but feel Ruby gives them an additional edge, names like the both the Prags, Justin Gehtland, Bruce Tate, David Geary et al should be enough to make Ruby worth looking at. But parochial as I may be I've been keeping my ear closest to ThoughtWorkers: people whose history I know and whose projects I can more easily check up on. It's still early days yet, but I now have a handful of project experiences to draw on. So far the results are firmly in favor of Ruby. When I ask the question "do you think you're significantly more productive in Ruby rather than Java/C#", each time I've got a strong 'yes'. This is enough for me to start saying that for a suitable project, you should give Ruby a spin. Which, of course, only leaves open the small question of what counts as 'suitable'. One thing to mention is that although we have a couple of what I might call typical web projects that fit in well with what's currently talked about as prime Rails territory, there are also elements that are different.
In all these cases, those involved said they are getting functionality, and value, faster out of the door than they had in other platforms. This suggests to me that if you're looking for delivery speed and productivity you should take a serious look at Ruby. There are still some open questions. In particular it's still too early to see what happens in later enhancement stages, particularly when you get team changes. Some people think that the dynamic nature of Ruby and the lack of tools will be a problem, others that the simplicity that Ruby encourages will make up for the difference. Such is the nature of the question that we can't really tell yet - I'll update you when I find out more. Cedric Beust argues effectively that even if Ruby is a superior platform it may not become mainstream. I certainly understand that argument, like many an ex-smalltalker I've long known of more productive platforms than the current mainstream enterprise choices. If it's important to you that you are only using mainstream platforms, you'll need to wait longer to see what happens. There are plenty of course, who don't care about following the mainstream. There's also plenty of projects where development productivity is swamped by political and other communication factors. Here Ruby's advantage would be significantly attenuated. But overall these experiences, from trusted colleagues mean I'm increasingly positive about using Ruby for serious work where speed, responsiveness, and productivity are important.
思归 on Ruby最新一期的《Dobb博士杂志》(2006年6月)的封面文章的标题为“Ruby On Rails--Java's Successor?”。该文对Ruby On Rails做了个综述性的介绍,同时还对Rails框架的作者David Heinemeier Hansson做了采访。 本月,业界著名人士Martin Fowler在他的bliki上发表了“EvaluatingRuby”的专文,也对Ruby做了推荐, http://www.martinfowler.com/bliki/EvaluatingRuby.html "...It's still early days yet, but I now have a handful of project experiences to draw on. So far the results are firmly in favor of Ruby. When I ask the question "do you think you're significantly more productive in Ruby rather than Java/C#", each time I've got a strong 'yes'. (虽然为期还早,但我现在能从ThoughtWorkers公司的多个项目的经验中获取一些结论。到目前为止,结果是看好Ruby。当我向参与Ruby项目的有关人员询问下面这个问题,“你是否认为,你使用 Ruby,比之于Java或C#,生产效率高出很多?”,每次的答复都是很坚定的,“是!”) ...In all these cases, those involved said they are getting functionality, and value, faster out of the door than they had in other platforms. This suggests to me that if you're looking for delivery speed and productivity you should take a serious look at Ruby. (在涉及的项目个案中,参与人员都说,与其他平台相比,他们推出功能和价值方面都比较快。在我看来,如果你的目的是交付速度和生产力,那么你应该认真地看一下Ruby。) ...But overall these experiences, from trusted colleagues mean I'm increasingly positive about using Ruby for serious work where speed, responsiveness, and productivity are important. (总的来说,我非常信任的同事的这些体验意味着,在那些注重速度,响应性以及生产力的严肃的工作中使用Ruby,我的看法是日趋肯定。)" 与此同时,我们尊敬的Don Box近来也写了不少针对Ruby的博客,涉及DSL,Block,与C#比较等内容。 在其中一文中,他说, http://pluralsight.com/blogs/dbox/archive/2006/04/27/22819.aspx "...From where I sit, Ruby has the language thought leadership position and is the competitor I hope AndersH is losing the most sleep over nowadays. (从我的角度来看,Ruby处于语言的思想领袖的地位,应该是让AndersH这些日子辗转难眠的竞争对手,我希望如此。)..."
>> http://blog.joycode.com/saucer/archive/2006/05/16/75824.aspx 5月7日 read rubyGemsref: docs.rubygems.org
Why did you create this thing? Beacuse we needed it! And needed it badly. 这是FAQ中的第一个问题,很有意思
是这样的,如果不需要就不要做,就会没动力做好
RubyGems Manuals
RubyGems User Guide About RubyGems
is the premier ruby packaging system. 1. 标准格式 2. easy to use 3. with gem server utility for serving gems 其实gem的起点非常好,使起来比较舒适的,一般来说 gem install xxx eg. gem install rails gem install rake 就OK了。 通过gem我们可以很轻松的install,remove,query gem packages. Features:
1. Easy installation and removal of RubyGems package 和他们的依赖关系。 2. 管理local packages 3. query, search and list local & remote packages 4. 支持packages多版本 5. 通过web的形式查看信息 6. easy to use interface for building gem packages 7. simple server for distributing your own gem packages 6,7蛮重要的,这也是我这次学习的重点 :)
基本概念
1. version 等待补充.. 2. listing
gem query --remote 除了支持gnu的选项,同样也支持unix的传统命令选项 gem q -R try it! 3.search
gem query --remote --name-matches doom # gem q -R doom 4. install a remote gem
gem install --remote rake # gem i -r rake 两个有用的开关 --gen-rdoc (maybe -rdoc) --run-tests 5. looking
gem spec rake try it!
6. browsing
输入gem_server 打开browser就可以看到RubyGems为你提供的页面,enjoy it. 7. using a config file
*nix下是.gemrc,windows下是gemconfigure.rb在site_ruby下 8. updating itself
gem update --system 这个还是很实用的,记得最早老是看到什么要升级到0.8.3版本,还要ruby setup.rb 呵呵,这样就方便了 使用通过Gem安装的软件包 这一步要解决的是如何从gem仓库中找到安装过的package 比如gem ins bluecloth,那如何才能在自己的代码中使用呢? 1. The Hard Way
最直接的方法便是在.rb中直接: require 'rubygems' require 'some_gem_library' # ..
2. -rubygems
在启动ruby的时候带上-rubygems开关 ruby -rubygems my_program_that_uses_gems 3. RUBYOPT
set RUBYOPT=rubygems 这样ruby启动时就自动带上了rubygems的开关 如果你是在windows上跑你会发现你什么都没做就可以在.rb中使用gem安装了的package。
why? 因为在安装比较新的ruby的时候一般都自动安装了gems,然后在环境变量中添加了RUBYOPT这个变量,将其值设为rubygems :) Coding with RubyGems 这块我就带过,对于版本的问题下次还要回过头来着重学习一下 现在接触的比较少,没什么发言权 等待补充.. 一般来说直接 require 'xx' 就ok了
因为gems对require做了手脚(当然是在打开rubygems这个开关后:)) 等待补充..(做了嘛手脚) Creating Your Own Gem 在UserGuide中只是一个skimpy overview.具体还要参考DeveloperGuide 一般来说分两步: * creating a gem specification file (rmagic.gemspec), which is Ruby code; and * running gem build my.gemspec to create the gem file (rmagic-2.1.gem) 这里还可以参考programming.ruby-2nd,大家应该都有吧
具体还要通过实践:) Distributing Gems
两种方法 1. 将build出来的gem放到internet上让人下载然后do a local install by gem. 显然不够爽 2. Remote Serving.
通过gem_server自己来做gem server。需要一台服务器...:( ref: TBD 3. 发布到RubyForge
这个是我们最感兴趣的,这里引一下全文: 8.3 Distributing on RubyForge You can make a gem available for manual download.
RubyForge (http://rubyforge.org) will automatically deploy any .gem file you upload to a project download area. I encourage you to get a RubyForge account and start a RubyForge project for your code. Even if you only use the file download area, it provides a mirror for your software for when your main site goes down.
呵呵,很简单吧,是我们想得太多...
4月12日 ruby 2则wapper = %{
<html>
<head><title> %s </title></head>
<body>
%s
</body>
</html>
}
p wapper
#=> <html>\n <head><title> %s </title></head>\n<body>\n%s </body>\n</html>
p wrapper %[nonocast home'', 'hello everybody!']
#=> <html>\n <head><title> nonocast home </title></head>\n<body>\nhello everybody! </body>\n</html>
you know?
ref: BlueCloth, Quiz(1), ERB
& another
class Host
def eval_in &block instance_eval(&block) end def method1 p "hello!" end end host = Host.new.eval_in { method1 }
以这种方式mixin俗称configuration block,这里注意Proc和lambda
最初我只能这样写:
class Host def state= (state) @state = state end def do_something @state.call(self) end end host = Host.new host.state = lambda {|host| p host } host.do_something 呵呵
ref:
& 谢谢徐八X 3月2日 在windows下通过dbi连接sqlserver20050.安装 BTW:要是看一下ADO.rb你就明白,原来其中是使用了ADODB这个COM,就是和asp非常像,当然你对数据库的操作接口都是用DBI的,ADODB作为具体的实现方式而已。 1.连接 那我们就可以在irb中试写: conn = DBI.connect("DBI:ADO:Provider=SQLOLEDB;Data Source=rssvr;Initial Catalog=testdb;User Id=rmsdbadmin;Password=123456;") ok没有异常,为了确保正确连接,我们可以: 最后关闭连接: 后面的就可以具体学习一下DBI,我这里也就起一个抛砖引玉的作用 2.具体 但需要提醒一下的是这里在do之后还需commit才会真正提交的数据库中 handle.BeginTrans() # start new Transaction 在你创建连接就子东打开了Transaction,这样一来就只有到commit也就是@handle.CommitTrans()后才会提交到数据库中 如果你想和asp中一样的话,把这句注释掉就ok了 select 2月27日 #!/usr/bin/ruby#!/usr/bin/ruby 在很多ruby的脚本都会有这句,在windows下成长的人很多都不明白,这似注释但每个脚本都有的玩意。 其实script的作用在linux的shell下可以发挥更大的威力。 说一下这句的作用: 明确请求由指定的shell来解释脚本 这起两个作用 1 提醒程序员使用何种shell 2 保证由指定的shell来执行脚本 #!/bin/bash 这个就是指定用bash这个shell来执行这个script |
|
|