随笔分类 - Ruby
摘要:link:http://www.markhneedham.com/blog/2008/10/02/ruby-unzipping-a-file-using-rubyzip/require 'rubygems'require 'zip/zip' def unzip_file (file, destina...
阅读全文
摘要:单引号内的内容,ruby会原样输出双引号内的内容,ruby会解析我们看个简单的例子,针对字符串 #{foo}test 我们分别用单引号核双引号操作'#{foo}test'=> "\#{foo}test" "#{foo}test"NameError: undefined local variable ormethod `foo' formain:Objectfrom (irb):4from C:/Ruby192/bin/irb:12:in`'显而易见, 双引号对字符串内的#进行了解析, 导致ruby认为foo是个方法,
阅读全文
摘要:在Ruby里只有false 和nil表示falseylink:https://gist.github.com/jfarmer/2647362
阅读全文
摘要:Installation:http://rubygems.org/gems/ci_reportersample rakefilerequire 'rake/testtask'require 'ci/reporter/rake/test_unit' # use this if you're using Test::UnitENV['CI_REPORT'] = 'test/reports' test = Rake::TestTask.new do |t| t.test_files = FileList['test/te
阅读全文
摘要:https://rubygems.org/pages/download如果你的Gem版本太低了,可以参考上面的链接说明,升级到合适的Version
阅读全文
摘要:链接地址: http://www.cnblogs.com/nbkhic/archive/2011/10/22/2221336.html ==========================================
阅读全文
摘要:Ruby里如果要Mixin的一个Module很简单class Test include Module1end但之前没有思考过能不能Mixin一个Class的功能? 答案是:可以,使用DelegateClassrequire 'delegate'class Assistant def initialize(name) @name = name end def read_email "(#{@name}) It is mostly spam." endendclass Manager < DelegateClass(Assistant) def initi
阅读全文
摘要:Ruby里ARGF可以将多个文件的内容合并成一个Stringputs ARGF.read // test.rb运行ruby test.rb a.txt b.txt后, a.txt和b.txt之中会被合并。更详细的讲解可以看考: http://ruby.about.com/od/tasks/ss/Argf-A-Shortcut-For-Scripts.htm
阅读全文
摘要:最近又在做RESTful的应用开发,自动化测试使用的Ruby写脚本。运用BDD/TDD的开发思路,希望能先从使用Mock表达行为开始这里使用如Ruby的webmock框架 (gem install webmock)来尝试require "test/unit"require "shoulda"require "webmock"include WebMock::APIinclude Test::Unit::Assertionsclass RESTfulTest < Test::Unit::TestCase context "
阅读全文
摘要:http://www.troubleshooters.com/codecorn/ruby/symbols.htmRuby 里的Symbol概念的讲解,What are symbols?It's a string. No it's an object. No it's a name.puts :Steve.class # output : Symbol ClassSymbol can not change at runtimeWhat can symbols do for you?A symbol is a way to pass string information,
阅读全文
摘要:这个功能要模拟Groovy中Expando和Javascript中的{},这里要用到ruby自带的osstruct库#!C:/Ruby192/bin/ruby.exerequire 'ostruct'def mytest puts "a method"end o = OpenStruct.newo.method1 = mytesto.prop1 = "a property"puts o.method1puts o.prop1
阅读全文
摘要:https://github.com/pivotal/jasmine-gem可参考上面的链接在Ruby中使用Jasmine,因为就是独立开发一个JavaScript的项目,所以我会使用 `jasmine init`来初始化一个项目。但当运行 `rake jasmine`的时候发现会错误产生, Google 了一下,找到一文章,试验过后发现可用。要修改对应的rakefile,多引入require 'yaml'sample case:begin require 'jasmine' require 'yaml' //自动生成的代码里是没这一行的 loa
阅读全文
摘要:desc "preview" task :preview do puts "preview" end desc 'want to say hello' task :hello , [:name, :from] => :preview do |t, args| puts "hello world, #{args[:name]} from #{args[:fro...
阅读全文
摘要:ruby comes with a set of predefined variables$: = default search path (array of paths)其他Ruby特殊变量:$! 最近一次的错误信息$@ 错误产生的位置$_ gets最近读的字符串$. 解释器最近读的行数(line number)$& 最近一次与正则表达式匹配的字符串$~ 作为子表达式组的最近一次匹配$n 最近匹配的第n个子表达式(和$~[n]一样)$= 是否区别大小写的标志$/ 输入记录分隔符$\ 输出记录分隔符$0 Ruby脚本的文件名$* 命令行参数$$ 解释器进程ID$? 最近一次执行的子进程
阅读全文
摘要:Apache Buildr是类似Ruby Rake的Build System。 和我之前学习的Groovy Gradle很像。准备在接下来的一段时间里加以学习。这次先介绍如何安装buildr. 我之前已经有在自己的机器上安装过JRuby,所以这次就直接用JRuby来安装。安装步骤也很简单:jruby –S gem install buildr 即可。可通过运行 buildr --verion来验证是否安装成功。Ruby和JRuby分别维护者不同的Gem Repository,所以你也可以以Ruby的方式下去安装,这里就不多述了。
阅读全文
摘要:如何在Ruby里,可以用#{}实现变量替换folder='test'system("ls-lrt#{folder}")上面的代码,会显示test目录。
阅读全文

浙公网安备 33010602011771号