# Help with meta programming

**URL:** <https://www.ruby-forum.com/t/help-with-meta-programming/179451>\
**Category:** Ruby\
**Created:** [November 25, 2009, 9:55am UTC](https://www.ruby-forum.com/t/help-with-meta-programming/179451 "2009-11-25T09:55:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [November 25, 2009, 9:55am UTC](https://www.ruby-forum.com/t/help-with-meta-programming/179451/1 "2009-11-25T09:55:17Z")

</div>

I came across the following code in a class called Marker

def when\_dropped  
self.listen\_to :event =\> :dragend do |script|  
script \<\< “drop\_location = #{self.var}.getLatLng();”

```
yield script, :drop_location

```

end  
end

if i use the function as follows

marker.when\_dropped do |script, drop\_location|  
logger.info(drop\_location)  
end

all i get is “drop\_location”. I want drop\_location to be evaluated to  
get the value from #{self.var}.getLatLng() and I can’t seem to find a  
way to do this, anyone have any ideas and/or know  
what exactly is going on here.

Thanks

---

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [November 25, 2009, 4:42pm UTC](https://www.ruby-forum.com/t/help-with-meta-programming/179451/2 "2009-11-25T16:42:54Z")

</div>

Sean Shillo wrote:

> I came across the following code in a class called Marker
> 
> def when\_dropped  
> self.listen\_to :event =\> :dragend do |script|  
> script \<\< “drop\_location = #{self.var}.getLatLng();”
> 
> ```
> yield script, :drop_location
> 
> ```
> 
> end  
> end
> 
> if i use the function as follows
> 
> marker.when\_dropped do |script, drop\_location|  
> logger.info(drop\_location)  
> end
> 
> all i get is “drop\_location”.

Right – because the parameter is the literal value :drop\_location, not  
a variable.

> I want drop\_location to be evaluated to  
> get the value from #{self.var}.getLatLng() and I can’t seem to find a  
> way to do this, anyone have any ideas and/or know

The getLatLng looks like it’s JavaScript, not Ruby. I’m assuming this  
is in the context of RJS or something that builds JS source code as a  
Ruby string. If that’s the case, then you’ll need to do the logging of  
that value on the JS side – Ruby can’t evaluate JS for you.

> what exactly is going on here.

You’re getting confused about what part of your code is in which  
language.

> Thanks

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
