This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if foo ! = 'blah' | |
puts "i expected 'blah' but foo contains #{{foo}}" | |
end | |
require "test/unit" | |
class MyThingieTest < Test::Unit::TestCase | |
def test_must_be_empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "json" | |
hash = { "Foo" => [Math::PI, 1, "kittens"], | |
"Bar" => [false, nil, true], "Baz" => { "X" => "Y" } } #... | |
puts hash.to_json #=> Outputs | |
{"Foo":[3.14159265358979,1,"kittens"],"Bar":[false,null,true],"Baz":{"X":"Y"}} | |
require "json" | |
json_string = '{"Foo":[3.14159265358979,1,"kittens"], ' + | |
'"Bar":[false,null,true],"Baz":{"X":"Y"}}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Standard ordinal arguments | |
def distance(x1,y1,x2,y2) | |
Math.hypot(x2 - x1, y2 - y1) | |
end | |
# Ordinal arguments, with an optional argument | |
def load_file(name,mode="rb") | |
File.open(name,mode) | |
end | |
# Pseudo-keyword arguments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "pstore" | |
# pay attention to the psstore;s usage | |
# @@data = PStore,new("filename.store") | |
# @@data[id] = <Ruby Object> should be surrounded by @@data.transition do <> end block | |
class User | |
def self.data | |
@data ||= PStore.new("users.store") #in class method, @data means the class instance variable. | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2) | |
builder.person { |b| b.name("Jim"); b.phone("555-1234") } | |
>> BasicObject.instance_methods | |
=> [:==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__] | |
class BlankSlate | |
class << self | |
def hide(name) | |
if instance_methods.include?(name) and name !~ /^(_|instance_eavl)/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RR | |
# RR (Double Ruby) is a test double framework that features a rich selection of double techniques and a terse syntax. | |
# | |
# | |
# one of the goal of RR is to make doubles more scannable. | |
# accomplished by making the double declartion look as much as the actual method invocation as possible | |
flexmock(User).should_receive(:find).with('42').and_return(jane) # Flexmock | |
User.should_receive(:find).with('42').and_return(jane) # Rspec | |
User.expects(:find).with('42').returns {jane} # Mocha | |
User.should_receive(:find).with('42') {jane} # Rspec using return value blocks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
== 克隆周边 == | |
在较老一代的版本控制系统里,checkout是获取文件的标准操作。你将获得一组特定保 | |
存状态的文件。 | |
在Git和其他分布式版本控制系统里,克隆是标准的操作。通过创建整个仓库的克隆来 | |
获得文件。或者说,你实际上把整个中心服务器做了个镜像。凡是主仓库上能做的事, | |
你都能做。 | |
=== 计算机间同步 === |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
== 揭开面纱 == | |
我们揭开Git神秘面纱,往里瞧瞧它是如何创造奇迹的。我会跳过细节。更深入的描述参见 http://www.kernel.org/pub/software/scm/git/docs/user-manual.html[ 用户手册]。 | |
=== 大象无形 === | |
直到你需要它的时候,而且那是你欢欣的时候,Git一直默默注视着你。 | |
Git简单地在你工作目录下的`.git`目录保存你项目的历史。 | |
=== 数据完整性 === |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
== 克隆周边 == | |
在较老的版本控制系统中,checkout是获取文件的标准操作。你讲获取一组特定保存状态的文件。 | |
在git等其他分布式控制系统中,clone是标准的操作。 | |
=== 计算机间同步 === | |
我可以忍受制作tar包或利用rsync来作备份和基本同步。但我有时在我笔记本上编辑,其他时间在台式机上,而且这俩之间也许并不交互。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
== 分支巫术 == | |
即时分支合并时Git最给力的杀手锏 | |
*方案* :Git有一个更好的工具对付这种情况,比克隆快多了而且节省空间: *git branch* 。 | |
使用这个魔咒,目录里的文件突然从一个版本变到另一个。除了只是在历史记录里上跳下窜外,这个转换还可以做更多。你的文件可以从上一个发布版变到实验版本到当前开发版本到你朋友的版本等等。 | |
=== 老板键 === |