From: Trans Date: 2008-03-03T06:40:44+09:00 Subject: Re: BlockChainable 0.0.1 released On Mar 2, 11:31 am, Drew Olson wrote: > BlockChainable is a module to aid in the creation of Domain Specific > Languages using block structure. By including BlockChainable into your > classes, you will be able to instantiate that class using the class name > itself, followed by any parameters to be passed to initialize, followed > by a block to be executed within the instantiated class. > > BlockChainable also allows methods to search up the chain of classes, > meaning that although a block is executed in the scope of the > instantiated class, any methods not found in the class but found in a > class "up-scope" will be called successfully on the up-scope class. This > chaining of method calls allows you to assert values within the blocks > as well as calling any other methods from "up-scope" classes. > > I know, I know, I need a better description :) Take a look at a usage > example more some simple ideas on using BlockChainable. And afterwards, > install it like so: He he. You could use Zope terminology, "acquisition" :) > sudo gem install block-chainable > > # a simple dsl for creating classroom rosters and printing them out. > code can be found in the > # example directory of BlockChainable. > > require 'block_chainable' > > # first, define our roster > class Roster > include BlockChainable > > def initialize(subject) > @subject = subject > @students = [] > end > > def add_student_to_roster student > @students << student > end > > def print_roster > puts "Roster for #{@subject}:" > @students.each{|s| puts " #{s}"} > end > end > > # next, define our student. the only tricky part here is > add_to_roster, which calls > # the method add_student_to_roster, which is actually defined on the > Roster class. > # BlockChainable will automatically send this method to the Roster > class with the > # Student instance as a parameter. So I take it that the Student class does'nt work on it's own because it would not be able to find #add_student_to_roster --sort of like the opposite of a class using a mixin and not providing a prerequisite method. This is an interesting library. I'm curious to see the underlying meta- programming. T.