Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Help with meta programming

Reply
Thread Tools

Help with meta programming

 
 
Sean Shillo
Guest
Posts: n/a
 
      11-25-2009
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
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Marnen Laibow-Koser
Guest
Posts: n/a
 
      11-25-2009
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.velocityreviews.com/forums/(E-Mail Removed)
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Meta-Meta-Programming, revisited Erik Veenstra Ruby 21 07-25-2006 10:26 PM
Meta-Meta-Programming Erik Veenstra Ruby 29 02-08-2006 08:22 PM
Meta methods to govern meta data? Duane Johnson Ruby 6 10-28-2005 03:57 AM
[Solution]: Lisp partial solution - meta-programming help Louis J Scoras Ruby 13 10-05-2005 06:56 AM
META NAME and META HTTP-EQUIV Nym Pseudo HTML 1 09-26-2003 09:13 AM



Advertisments