Some Rules from wrting your own dsl with ruby_Ruby_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > Ruby > Some Rules from wrting your own dsl with ruby

Some Rules from wrting your own dsl with ruby

 2011/11/11 16:37:22  Goldice  http://jdoc.iteye.com  我要评论(0)
  • 摘要:来自:http://blog.nofail.de/2010/02/writing-your-own-dsl-with-ruby/SomeRulesfromwrtingyourowndslwithruby1.lettheuserchoosehowtouseitallimplementedmethodsreturntheobjectinstanceitself,soonecanchainmethodcallsforconvenient2
  • 标签:Ruby

来自:http://blog.nofail.de/2010/02/writing-your-own-dsl-with-ruby/

?

Some Rules from wrting your own dsl with ruby

?

1. let the user choose how to use it

?

all implemented methods return the object instance itself,so one can chain method calls for convenient

?

2. make options optional

?

a well designed API does not force user to provide argument that are not mandatory

?

3. make use of an option hash for defaults

?

consider using an optional parameter hash as the last method argument

?

4. make use of scoped blocks

?

providing scopes is another way to improve the readability of your code

?

5. make use of instance_eval

?

rebuid do?

method1

method2

method3?

end

?

6. consider implementing method_missing

发表评论
用户名: 匿名