`
Goldice
  • 浏览: 108146 次
  • 性别: 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
分享到:
评论

相关推荐

    Resources & Stream Reading & Wrting

    在C++Builder6中,资源管理和流的读写是编程中的关键部分,特别是在处理应用程序内部数据或与外部数据交互时。资源通常指的是程序运行时所需的非代码元素,如图像、声音、文本等。内存流则允许我们将数据在内存中...

    On Writing Well 2006 (30th Anniversary Edition)

    It is a book for everybody who wants to learn how to write or who needs to do some writing to get through the day, as almost everybody does in the age of e-mail and the Internet. Whether you want to ...

    flash_all_lock.bat

    flash_all_lock.bat

    abt-coding

    在给定的“abt-coding”项目中,我们可以看到一个典型的前端-后端开发流程。这个项目似乎使用了现代的开发工具和技术栈,主要基于JavaScript。以下是对这些信息的详细解析: 首先,"前端"部分指示我们关注的是网站...

Global site tag (gtag.js) - Google Analytics