Help with meta programming

Discussion in 'Ruby' started by Sean Shillo, Nov 25, 2009.

  1. Sean Shillo

    Sean Shillo Guest

    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/.
    Sean Shillo, Nov 25, 2009
    #1
    1. Advertising

  2. 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

    --
    Posted via http://www.ruby-forum.com/.
    Marnen Laibow-Koser, Nov 25, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nym Pseudo

    META NAME and META HTTP-EQUIV

    Nym Pseudo, Sep 26, 2003, in forum: HTML
    Replies:
    1
    Views:
    545
    =?iso-8859-1?Q?brucie?=
    Sep 26, 2003
  2. Louis J Scoras
    Replies:
    13
    Views:
    313
    Dave Burt
    Oct 5, 2005
  3. Duane Johnson

    Meta methods to govern meta data?

    Duane Johnson, Oct 25, 2005, in forum: Ruby
    Replies:
    6
    Views:
    234
    Adam Sanderson
    Oct 28, 2005
  4. Erik Veenstra

    Meta-Meta-Programming

    Erik Veenstra, Feb 7, 2006, in forum: Ruby
    Replies:
    29
    Views:
    375
    Erik Veenstra
    Feb 8, 2006
  5. Erik Veenstra

    Meta-Meta-Programming, revisited

    Erik Veenstra, Jul 21, 2006, in forum: Ruby
    Replies:
    21
    Views:
    433
    Erik Veenstra
    Jul 25, 2006
Loading...

Share This Page