# Where can I find eval rules for ruby?

**URL:** <https://www.ruby-forum.com/t/where-can-i-find-eval-rules-for-ruby/112138>\
**Category:** Ruby\
**Created:** [August 15, 2007, 7:49pm UTC](https://www.ruby-forum.com/t/where-can-i-find-eval-rules-for-ruby/112138 "2007-08-15T19:49:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daryoush\_Mehrtash](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/838e76/32.png) [@Daryoush\_Mehrtash](https://www.ruby-forum.com/u/Daryoush_Mehrtash)\
**Post date:** [August 15, 2007, 7:49pm UTC](https://www.ruby-forum.com/t/where-can-i-find-eval-rules-for-ruby/112138/1 "2007-08-15T19:49:18Z")

</div>

Can anyone point me to a specification on Ruby’s evaluation rules?

I am trying to understand Domain Specific Language implementation in  
Ruby,  
there are lot of examples such as  
[Evaluation Options in Ruby](http://www.infoq.com/articles/eval-options-in-ruby), but I can’t find a  
definitive guide on the interpreters rule for evaluating a line of DSL  
String in instance\_eval call.

thanks for your help

daryoush

---

<div class="post-metadata">

**Author:** ![Daryoush\_Mehrtash](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/838e76/32.png) [@Daryoush\_Mehrtash](https://www.ruby-forum.com/u/Daryoush_Mehrtash)\
**Post date:** [August 15, 2007, 8:22pm UTC](https://www.ruby-forum.com/t/where-can-i-find-eval-rules-for-ruby/112138/2 "2007-08-15T20:22:23Z")

</div>

Daryoush Mehrtash wrote:

> I am trying to understand Domain Specific Language implementation in Ruby,  
> there are lot of examples such as  
> [http://www.infoq.com/articles/eval-options-in-ruby](http://www.infoq.com/articles/eval-options-in-ruby), but I can’t find a  
> definitive guide on the interpreters rule for evaluating a line of DSL  
> String in instance\_eval call.

DSL is a state of mind, not a language inside a string inside a  
language.

The state of mind is that you intend to write in one language style,  
inside another language. For example, Rake is a _light_ form of rule  
solver, so you can write it in a format paralleling a Makefile:

task :rule\_1 =\> [:rule\_2, :rule\_C] do  
evaluate\_rule\_1  
end

To write in a declarative mode, write object methods with store their  
commands in an engine, and then process the engine. Here’s a little  
Flea script to draw a spiral:

egg = startOvum(18, 45, 100)  
ax = egg.newRootAxiom(‘A’)  
b = egg.newAxiom(‘B’)

ax.longer(6).right.color(1).gosub(b)  
b.tube.shorter(0.8).left.link(b)  
render egg

The commands like longer, right, color, etc are turtle graphics  
describing a shape. render then outputs the shape.

All the ActiveRecord association commands - has\_many, belongs\_to, etc

- qualify as DSLs too. The goal is to give your user-programmer a  
clear but deep interface, so they can write the command they need, in  
the relevant context they need, and the engine on the inside hides the  
complexity.

---

<div class="post-metadata">

**Author:** ![Daryoush\_Mehrtash](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/838e76/32.png) [@Daryoush\_Mehrtash](https://www.ruby-forum.com/u/Daryoush_Mehrtash)\
**Post date:** [August 15, 2007, 9:04pm UTC](https://www.ruby-forum.com/t/where-can-i-find-eval-rules-for-ruby/112138/3 "2007-08-15T21:04:27Z")

</div>

This is exactly the issue I am trying to understand:

To write in a declarative mode, write object methods with store their

> commands in an engine, and then process the engine.

I need to understand the object methods I would need to support the  
evaluation, and the sequence of calls.

For example, let say I create and object instance and instance\_eval  
the following:

if the ‘$1-$2 No Limit’ list is more than 15 then notify the floor to  
open

this seems to result in  
(than 15)  
(more (than 15))  
(is (more (than 15))) …

What I am looking for is the rule that the ruby interpreter uses to  
evaluate  
a given script.

daryoush

On 8/15/07, Phlip [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> DSL is a state of mind, not a language inside a string inside a language.  
> commands in an engine, and then process the engine. Here’s a little  
> The commands like longer, right, color, etc are turtle graphics  
> [http://www.oreilly.com/catalog/9780596510657/](http://www.oreilly.com/catalog/9780596510657/)  
> ^ assert\_xpath  
> [O'Reilly Media - Technology and Business Training](http://tinyurl.com/yrc77g) ← assert\_latest Model

–  
Daryoush

Weblog: [http://perlustration.blogspot.com/](http://perlustration.blogspot.com/)
