# Analyze ruby conditional expression

**URL:** <https://www.ruby-forum.com/t/analyze-ruby-conditional-expression/159751>\
**Category:** Ruby\
**Created:** [February 8, 2009, 11:09am UTC](https://www.ruby-forum.com/t/analyze-ruby-conditional-expression/159751 "2009-02-08T11:09:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![GSSSSbor\_SebestySSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@GSSSSbor\_SebestySSS](https://www.ruby-forum.com/u/GSSSSbor_SebestySSS)\
**Post date:** [February 8, 2009, 11:09am UTC](https://www.ruby-forum.com/t/analyze-ruby-conditional-expression/159751/1 "2009-02-08T11:09:29Z")

</div>

Hi,

I want to examine conditional expressions and I’m looking for tools to  
do it.  
It would be perfect to do it purely in ruby or even in jruby.

Any recommendations are apprecitated.

Gábor

---

<div class="post-metadata">

**Author:** ![GSSSSbor\_SebestySSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@GSSSSbor\_SebestySSS](https://www.ruby-forum.com/u/GSSSSbor_SebestySSS)\
**Post date:** [February 8, 2009, 11:45am UTC](https://www.ruby-forum.com/t/analyze-ruby-conditional-expression/159751/2 "2009-02-08T11:45:14Z")

</div>

On Sun, Feb 8, 2009 at 11:03 AM, Gábor Sebestyén [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> I want to examine conditional expressions and I’m looking for tools to do it.  
> It would be perfect to do it purely in ruby or even in jruby.
> 
> Any recommendations are apprecitated.
> 
> Gábor

I am not sure what a conditional expression is, care to give some  
examples?  
Robert

---

<div class="post-metadata">

**Author:** ![GSSSSbor\_SebestySSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@GSSSSbor\_SebestySSS](https://www.ruby-forum.com/u/GSSSSbor_SebestySSS)\
**Post date:** [February 8, 2009, 1:36pm UTC](https://www.ruby-forum.com/t/analyze-ruby-conditional-expression/159751/3 "2009-02-08T13:36:06Z")

</div>

On 08.02.2009 11:03, Gábor Sebestyén wrote:

> I want to examine conditional expressions and I’m looking for tools to do it.

What exactly does “examine” mean in this context? If you want to  
execute them and see results or execute parts of them, why is IRB not  
sufficient?

Cheers

robert

---

<div class="post-metadata">

**Author:** ![GSSSSbor\_SebestySSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@GSSSSbor\_SebestySSS](https://www.ruby-forum.com/u/GSSSSbor_SebestySSS)\
**Post date:** [February 9, 2009, 9:52am UTC](https://www.ruby-forum.com/t/analyze-ruby-conditional-expression/159751/4 "2009-02-09T09:52:56Z")

</div>

2009/2/8 Gábor Sebestyén [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> if B  
> do\_something2  
> end
> 
> If A and B equals their conditional branches could be joined.
> 
> I’m investigating how it would be easy evaluate A and B whether they  
> are both true or false.  
> I need this in my refactoring experiment.

You are aware that expressions A and B can have side effects which  
makes it practically impossible to decide on the equivalence? Keep in  
mind that Ruby is not a pure functional language.

Cheers

robert

---

<div class="post-metadata">

**Author:** ![GSSSSbor\_SebestySSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@GSSSSbor\_SebestySSS](https://www.ruby-forum.com/u/GSSSSbor_SebestySSS)\
**Post date:** [February 9, 2009, 11:08am UTC](https://www.ruby-forum.com/t/analyze-ruby-conditional-expression/159751/5 "2009-02-09T11:08:39Z")

</div>

On Mon, Feb 9, 2009 at 4:22 AM, GÃ¡bor SebestyÃ©n [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> if B

if A && B then  
“bingo”  
elsif(A) then  
“bango”  
elsif(B)  
“bongo”  
else  
nil  
end

This is just a guess, but you could also use a nested if or a case.  
case(a)  
when !a | b then “a=t, b=t”  
when !(a & b) then “a=t, b=f”  
when !(a | b) then “a=f, b=t”  
when !a & b then “a=f, b=f”  
end

But that would be wierd.

case(

---

<div class="post-metadata">

**Author:** ![GSSSSbor\_SebestySSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@GSSSSbor\_SebestySSS](https://www.ruby-forum.com/u/GSSSSbor_SebestySSS)\
**Post date:** [February 8, 2009, 7:23pm UTC](https://www.ruby-forum.com/t/analyze-ruby-conditional-expression/159751/6 "2009-02-08T19:23:24Z")

</div>

For instance, I want to decide whether the conditional expressions of  
two subsequent IFs are the same (or equivalent). I know it’s not easy  
in most cases.

Let’s see a primitive example:

if A then  
do\_something1  
end

if B  
do\_something2  
end

If A and B equals their conditional branches could be joined.

I’m investigating how it would be easy evaluate A and B whether they  
are both true or false.  
I need this in my refactoring experiment.

Gábor
