Help with meta programming

S

Sean Shillo

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
 
M

Marnen Laibow-Koser

Sean said:
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.

Best,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Meta-Meta-Programming 29
Looking to change programming direction 1
Help with code 0
meta-programming 6
#meta 15
Help with my responsive home page 2
Trouble with code 2
Help with Loop 0

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top