nasser / zajal

Experimental creative coding framework
MIT License
161 stars 10 forks source link

Zajal method visibility in Sketch classes #68

Open nasser opened 11 years ago

nasser commented 11 years ago

Zajal's modules get included into the Sketch class here lib/core/sketch.rb. This is beneficial and avoids namespace pollution, but breaks code like this

class Particle
  def draw
    # Particle can't see Graphics#cirlcle, because Graphics wasn't included into it
    circle @x, @y, 20 
  end
end

draw do
  p = Particle.new
  p.draw
end
nasser commented 11 years ago

I'm not 100% sure how to tackle this. Any ideas, @judy?

judy-zz commented 11 years ago

I did some research, but I haven't found anything yet. I'd love to see if there's a way to overwrite Class generation, so each time a Class is defined, we automatically define #method_missing. So if a user writes circle, and it's not defined in the class, our method_missing picks up on it, and is able to defer it to Graphics if possible. Not sure.

Otherwise, we'll just have to communicate that you need to include Graphics if you're doing graphics in your class.