`

First DSL With Ruby

 
阅读更多
test_event.rb
event "an event that always happens" do
    110 > @target_sales
end


setup do
    puts "Setting up sky"
    @target_sales = 100
end





main.rb
proc {
    events={}
    setups=[]
    
    send :define_method, :event do |name, &block|
       events[name] = block
    end
    
    send :define_method, :setup do  |&block|
       setups << block
    end
    
    send :define_method, :each_event do |&block|
        events.each_pair do | name, event |
            block.call name, event
        end
    end 
    
    send :define_method, :each_setup do |&block|
        setups.each do | setup|
            block.call setup
        end
    end
    
}.call


Dir.glob('*events.rb').each do |file|
    # @events={}
    # @setups=[]
    puts file
    load file
    each_event do |name, event|
        env = Object.new
        each_setup do |setup|
             env.instance_eval &setup
        end 
       
        puts "ALERT #{name}" if env.instance_eval &event
    end 
end 

分享到:
评论

相关推荐

    Head First Ruby.pdf

    This Head First guide teaches you the Ruby language in a concrete way that gets your neurons zapping and helps you become a Ruby genius. You'll enter at Ruby's language basics and work through ...

    Head First Ruby epub

    Head First Ruby 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书

    Head First Ruby 英语原版

    ### 关于《Head First Ruby》的关键知识点 #### 一、书籍基本信息 - **书名**:《Head First Ruby》 - **作者**:Jay McGavren - **出版年份**:2015年 - **出版社**:O’Reilly Media, Inc. - **ISBN**:978-1-...

    Data Science from Scratch First Principles with Python 无水印pdf

    Data Science from Scratch First Principles with Python 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自...

    [深入浅出HTML].Head.First.HTML.with.CSS.and.XHTML.pdf

    With Head First HTML with CSS & XHTML, you’ll avoid the embarrassment of thinking web-safe colors still matter, and the foolishness of slipping a font tag into your pages. Best of all, you’ll learn ...

    Head first HTML with CSS and XHTM

    《Head First HTML with CSS and XHTML》是一本专为初学者设计的HTML、CSS与XHTML学习书籍,以其独特的教学方式赢得了广泛赞誉。这本书通过生动、直观的视觉呈现和易理解的实例,帮助读者快速掌握网页制作的基础知识...

    First Contact With TensorFlow

    本书《First Contact With TensorFlow》由Jordi Torres教授编写,旨在为读者提供一个入门级的指南,帮助他们快速掌握TensorFlow的基本操作及应用技巧。 #### 二、TensorFlow基础知识 ##### 1. TensorFlow的核心...

    Code-First Development with Entity Framework

    他的书《Code-First Development with Entity Framework》不仅涉及到Code-First开发模式的基础知识,还涵盖了进阶技术,帮助开发者将数据访问技能提升到一个新水平。由于版权和法律保护的原因,书中内容不得随意复制...

    Apress Pro ActiveRecord Databases with Ruby and Rails.pdf

    《Pro ActiveRecord:Databases with Ruby and Rails》这本书深入探讨了如何使用ActiveRecord这一对象关系映射(Object Relational Mapping, ORM)工具来管理和操作数据库,特别是在Ruby on Rails框架中的应用。...

    Matlab - Chemical Process Control a first Course with MATLAB

    《Matlab - Chemical Process Control a first Course with MATLAB》是一本专为化学工程学生和从业者设计的教材,旨在介绍如何利用MATLAB这一强大的计算工具来理解和分析化学过程控制系统。本书深入浅出地阐述了控制...

    《Head First HTML with CSS & XHTML》书籍代码资源

    《Head First HTML with CSS & XHTML》是一本广受欢迎的IT教育书籍,专注于教授初学者如何构建和设计网页。这本书以其独特的教学方式,采用生动、直观的图像和互动性极强的例子,帮助读者深入理解HTML(超文本标记...

    Data Science from Scratch - First Principles with Python.2015

    Joel Grus ■■ Get a crash course in Python ■■ Learn the basics of linear algebra, statistics, and probability— and understand how and when they're used in data science ■■ Collect, explore, clean...

Global site tag (gtag.js) - Google Analytics