On Wed, Feb 17, 2010 at 12:00 AM, Dave @ UPENN <[email protected]> wrote:
>
> BUT when i was calling it in a rails activerecord, 'self' appears to
> be overwritten in the Dsl.  so I had to reassign any of those methods
> to a variable..

Hi Dave,

there is no overwriting in the DSL.

Consider that piece of Ruby code :

---8<---
def generate
  p [ :generate, self ]
  R.pdef
end

module R
  def self.pdef
    p [ :pdef, self ]
  end
end

generate
--->8---

It will return

---8<---
$ ruby t.rb
[:generate, main]
[:pdef, R]
--->8---

Or that one :

---8<---
def generate
  p [ :generate, self ]
  C.new.pdef
end

class C
  def pdef
    p [ :pdef, self ]
  end
end

generate
--->8---

which gives :

---8<---
$ ruby t.rb
[:generate, main]
[:pdef, #<C:0x100156160>]
--->8---

See, no overwriting, just regular Ruby behaviour.

Now you may want to read about "closures" :

  http://en.wikipedia.org/wiki/Closure_%28computer_science%29

Maybe this article about Ruby and closures might suit you :

  http://martinfowler.com/bliki/Closure.html

Please read it carefully.

You are just dealing with a bit more advanced Ruby concepts. There is
no Rails or ruote interference with your code, no overwriting, no
magic.


Best regards,

-- 
John Mettraux   -   http://jmettraux.wordpress.com

-- 
you received this message because you are subscribed to the "ruote users" group.
to post : send email to [email protected]
to unsubscribe : send email to [email protected]
more options : http://groups.google.com/group/openwferu-users?hl=en

Reply via email to