`
Goldice
  • 浏览: 107744 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Some Rules from wrting your own dsl with 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

0
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics