# How does ez\_where catch =~ and co

**URL:** <https://www.ruby-forum.com/t/how-does-ez-where-catch-and-co/70975>\
**Category:** Rails\
**Created:** [October 4, 2006, 1:12pm UTC](https://www.ruby-forum.com/t/how-does-ez-where-catch-and-co/70975 "2006-10-04T13:12:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![liquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@liquid](https://www.ruby-forum.com/u/liquid)\
**Post date:** [October 4, 2006, 1:12pm UTC](https://www.ruby-forum.com/t/how-does-ez-where-catch-and-co/70975/1 "2006-10-04T13:12:19Z")

</div>

Hi all,

I’ve been looking through the ez\_where plugin and I’m slowly starting to  
follow it. One thing that I can’t quite grok is how the  
=~ , == , === etc methods are caught in the block.

eg in the readme

condition :my\_other\_table do  
id === [1, 3, 8]  
foo == ‘other bar’  
fiz =~ ‘%faz%’  
end

I can see how the id, foo and fiz methods are caught by using  
method\_missing, but I can’t find out how the =~ and it’s argument is  
then  
subsequently caught to be processed.

Can anyone point out how this is done please.

Thanx

---

<div class="post-metadata">

**Author:** ![liquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@liquid](https://www.ruby-forum.com/u/liquid)\
**Post date:** [October 4, 2006, 8:31pm UTC](https://www.ruby-forum.com/t/how-does-ez-where-catch-and-co/70975/2 "2006-10-04T20:31:06Z")

</div>

On Oct 4, 2006, at 4:08 AM, Daniel N wrote:

> fiz =~ ‘%faz%’  
> end I can see how the id, foo and fiz methods are caught by using  
> method\_missing, but I can’t find out how the =~ and it’s argument  
> is then subsequently caught to be processed.
> 
> Can anyone point out how this is done please.
> 
> Thanx

Hey Daniel-

```
Its actually a dual method_missing dispatch. the id and foo are

```

caught in Condition by method missing and then they create a new  
Clause object for each statement. In the Clause object, method  
missing catches the == =~ and other operators. Thats the simplified  
explanation anyway. Its quite a complex interaction that has taken us  
a while to build up and make work.

```
Make sure you check out the new version released yesterday!

```

[http://brainspl.at/articles/2006/10/03/nested-joins-and-ez-where-update](http://brainspl.at/articles/2006/10/03/nested-joins-and-ez-where-update)

-Ezra

---

<div class="post-metadata">

**Author:** ![liquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@liquid](https://www.ruby-forum.com/u/liquid)\
**Post date:** [October 5, 2006, 2:05am UTC](https://www.ruby-forum.com/t/how-does-ez-where-catch-and-co/70975/3 "2006-10-05T02:05:34Z")

</div>

On 10/5/06, Ezra Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> explanation anyway. Its quite a complex interaction that has taken us  
> a while to build up and make work.
> 
> ```
> Make sure you check out the new version released yesterday!
> 
> ```
> 
> [Ruby on Rails Blog / What is Ruby on Rails for?](http://brainspl.at/articles/2006/10/03/nested-joins-and-ez-where-update)
> 
> -Ezra

Hi Ezra,

Thanx for the response. The code is pretty tricky for me to grok.

Hopefully you don’t mind but I’m looking for some inspiration to create  
a  
plugin to generate nested conditions for javascript.

Basically I’m thinking of a plugin that has similar syntax to ez\_where  
that  
generates conditions based on DOM elements that I can use in an if  
statement  
to control behaviors and functions on the client side in javascript.

Then I could generate complex conditional statement that conditionally  
controlled the visiblity of elements etc.

Does this sound like something that might be useful? When I was looking  
through ez\_where I was thinking that the logic for the nested conditions  
is  
essentially the same, with only the output needing to change. I’m not  
sure  
if that’s true when thinking of dom elements but it’s a place to start.

Thanx to you and Fabien for writing such a great plugin.

Cheers

---

<div class="post-metadata">

**Author:** ![liquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@liquid](https://www.ruby-forum.com/u/liquid)\
**Post date:** [October 5, 2006, 3:33am UTC](https://www.ruby-forum.com/t/how-does-ez-where-catch-and-co/70975/4 "2006-10-05T03:33:39Z")

</div>

Hi~

On Oct 4, 2006, at 5:04 PM, Daniel N wrote:

> ez\_where that generates conditions based on DOM elements that I can  
> dom elements but it’s a place to start.
> 
> Thanx to you and Fabien for writing such a great plugin.
> 
> Cheers

Hey Daniel-

```
I am not entirely sure what you want to do here. Are you trying to

```

program this in javascript? Or do you mean a ruby/rails coded plugin  
that will generate javascript for you? Can you provide me with some  
examples of what you are trying to generate and what you would want  
your ruby syntax for this to look like? I might be able to point you  
in the right direction.

Cheers-  
-Ezra

---

<div class="post-metadata">

**Author:** ![liquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@liquid](https://www.ruby-forum.com/u/liquid)\
**Post date:** [October 5, 2006, 4:31am UTC](https://www.ruby-forum.com/t/how-does-ez-where-catch-and-co/70975/5 "2006-10-05T04:31:42Z")

</div>

On 10/5/06, Ezra Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Cheers-  
> -Ezra

I’m not exacly sure myself yet of the grand scheme.

At the moment, the overall outcome I want to achive is to be able to  
conditionally control visibilty of DOM objects in response to activity  
in  
the DOM, especially forms.

Something like

form.condition( ‘element5’, :hide ) do  
or do  
field2 == “go”  
and do  
thing.hidden?  
field1 =~ /bla/  
end  
end  
end

to construct

if ( field2.value = “go” || (thing.style.display = “none” &&  
field1.value.match( ‘bla’ ) ) ) { hide\_if\_shown( element5 ); }

I’m not sure I’m happy with the sytax yet. It looks a bit nasty.

This should be added to an array of conditions that observes form fields  
and  
gets fired when something happens.

I’d really like to do this in ruby and not need to resort to raw js  
unless  
nessesary, I’ve been checking out UJS today and that looks like it’s  
pretty  
nice.

I figured that to do this, first I need to generate the condition inside  
the  
if statement. Hence my sudden interest in how to construct nested  
queries.

I’m hoping that this will lead me to highly interactive and intelligent  
forms for the occasions where a large form is required for everything,  
but  
not everything needs to be filled out, or even wizard style forms on one  
page.

Do you have any thoughts on whether this is a reasonable idea or not?  
Any  
potholes that would be likely if using such a plugin?
