# \[ANN\] BlockChainable 0.0.1 released

**URL:** <https://www.ruby-forum.com/t/ann-blockchainable-0-0-1-released/130726>\
**Category:** Ruby\
**Created:** [March 2, 2008, 5:31pm UTC](https://www.ruby-forum.com/t/ann-blockchainable-0-0-1-released/130726 "2008-03-02T17:31:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dfg59](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e0b2c6/32.png) [@dfg59](https://www.ruby-forum.com/u/dfg59)\
**Post date:** [March 2, 2008, 5:31pm UTC](https://www.ruby-forum.com/t/ann-blockchainable-0-0-1-released/130726/1 "2008-03-02T17:31:28Z")

</div>

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:

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.

class Student  
include BlockChainable

```
def add_to_roster
  add_student_to_roster self
end

def to_s
  "#{@last_name}, #{@first_name} - age #{@age}"
end

def first_name name
  @first_name = name
end

def last_name name
  @last_name = name
end

def age years
  @age = years
end

```

end

# we now have all the pieces we need for creating a simple dsl for

building

# and printing a class roster

Roster :Math do  
Student do  
first\_name “Drew”  
last\_name “Olson”  
age 25

```
  add_to_roster
end

Student do
  first_name "John"
  last_name "Doe"
  age 17

  add_to_roster
end

Student do
  first_name "Jane"
  last_name "Doe"
  age 19

  add_to_roster
end

print_roster

```

end

---

<div class="post-metadata">

**Author:** ![dfg59](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e0b2c6/32.png) [@dfg59](https://www.ruby-forum.com/u/dfg59)\
**Post date:** [March 2, 2008, 10:41pm UTC](https://www.ruby-forum.com/t/ann-blockchainable-0-0-1-released/130726/2 "2008-03-02T22:41:44Z")

</div>

On Mar 2, 11:31 am, Drew O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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” 🙂

> ```
> include BlockChainable
> def print_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.

---

<div class="post-metadata">

**Author:** ![dfg59](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e0b2c6/32.png) [@dfg59](https://www.ruby-forum.com/u/dfg59)\
**Post date:** [March 3, 2008, 7:09pm UTC](https://www.ruby-forum.com/t/ann-blockchainable-0-0-1-released/130726/3 "2008-03-03T19:09:08Z")

</div>

Trans wrote:

> On Mar 2, 11:31 am, Drew O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > 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” 🙂
> 
> > ```
> > include BlockChainable
> > def print_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.

Trans -

You’re exactly right. I actually considered now including the example  
because of this, but I thought it clarified some of the ideas from the  
description. If we wanted to remove the coupling, I could actually just  
call the Roster method directly from the Student block, passing self as  
the argument. I didn’t like having to pass self, so I encapsulated the  
call into a student method, but, as you said, this does tie the Student  
implementation to the Roster implemetation. I’ll consider changing this  
example.

As far as the meta-programming, download the source 🙂 It’s only 30  
lines of meta-goodness.

- Drew
