# A dumb question on extracting a value from a hash

**URL:** <https://www.ruby-forum.com/t/a-dumb-question-on-extracting-a-value-from-a-hash/53307>\
**Category:** Rails\
**Created:** [February 1, 2006, 12:54am UTC](https://www.ruby-forum.com/t/a-dumb-question-on-extracting-a-value-from-a-hash/53307 "2006-02-01T00:54:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [February 1, 2006, 12:54am UTC](https://www.ruby-forum.com/t/a-dumb-question-on-extracting-a-value-from-a-hash/53307/1 "2006-02-01T00:54:55Z")

</div>

Hi,  
I have the following code fragment;

@comm\_type = Communication.find\_by\_sql(‘select id from  
communication\_types where upper(description) = “EMAIL”’)

Which results in

> > @comm\_type  
> > =\> [#\<Communication:0x39a0f60 @attributes={“id”=\>“4”}\>]

But when I try to test an ActiveREcord against this it doesn’t work;

@recipient.communications.each do |comm|  
if comm.communications\_type\_id == @comm\_type  
@email\_address = comm.code  
end  
end

What do I need to write to get at that value in the hash. Sorry it’s  
such a dumb question :~(

Cheers,  
Eric.

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [February 1, 2006, 1:03am UTC](https://www.ruby-forum.com/t/a-dumb-question-on-extracting-a-value-from-a-hash/53307/2 "2006-02-01T01:03:57Z")

</div>

On Jan 31, 2006, at 3:51 PM, Eric S. wrote:

> But when I try to test an ActiveREcord against this it doesn’t work;
> 
> @recipient.communications.each do |comm|  
> if comm.communications\_type\_id == @comm\_type  
> if comm.communications\_type\_id == @comm\_type.id
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

I think thats all your missing

Cheers-  
-Ezra Z.  
Yakima Herald-Republic  
WebMaster

> **[yakimaherald.com | Yakima, Washington - We Tell Your Stories](https://www.yakimaherald.com/)**

509-577-7732  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [February 1, 2006, 1:10am UTC](https://www.ruby-forum.com/t/a-dumb-question-on-extracting-a-value-from-a-hash/53307/3 "2006-02-01T01:10:01Z")

</div>

Hi Ezra,  
Nope - I tried that (and a few other combinations) @comm\_type.id is  
returning the id of the hash not the id within the hash. I’d have  
expected to get the attribute 4 too, but noooo  
Eric.

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [February 1, 2006, 1:16am UTC](https://www.ruby-forum.com/t/a-dumb-question-on-extracting-a-value-from-a-hash/53307/4 "2006-02-01T01:16:06Z")

</div>

Eric-

```
Ahh your right. Ok well this will work:

```

@comm\_type[0][:id]

Cheers-  
-Ezra

On Jan 31, 2006, at 4:09 PM, Eric S. wrote:

> > > ```
> > > if comm.communications_type_id == @comm_type
> > > 
> > > ```
> > 
> > [http://yakimaherald.com](http://yakimaherald.com)  
> > 509-577-7732  
> > removed\_email\_address@domain.invalid
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

-Ezra Z.  
Yakima Herald-Republic  
WebMaster

> **[yakimaherald.com | Yakima, Washington - We Tell Your Stories](https://www.yakimaherald.com/)**

509-577-7732  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [February 1, 2006, 1:25am UTC](https://www.ruby-forum.com/t/a-dumb-question-on-extracting-a-value-from-a-hash/53307/5 "2006-02-01T01:25:08Z")

</div>

Hi Ezra - Many Thanks. Works just like a bought one!!  
Eric.
