How do I use Ruby1.9 with Shoes?
Question
Shoes wraps it's own Ruby install, right?
I can't use Fiber which is a Ruby1.9 feature. And, I want to use a Fiber for creating a generator.
Here's my code (so you can make sure the problem isn't with my code):
class BrownianGenerator
def initialize
@x = 0
@fiber = Fiber.new do
loop do
@x = @x+rand;
Fiber.yield @x
end
end
end
def next; @fiber.resume end
def rewind; @x=0 end
end
and if I made a shoes app like this:
Shoes.app do
@b = BrownianGenerator.new
end
if I pull up the shoes console, I see the error:
uninitialized constant #<class:0xblah>::BrownianGenerator::Fiber
Since, it's saying Fiber is an uninitialized constant, either something is wrong with my code or this Ruby version doesn't know about the Fiber class - the latter should be the case.
I saw this question on determining the version of Ruby (which is 1.8 for my mac install), but I don't know how I would change the version.
Solution
or you could use aman gupta's "poor man's fibers" or try doing ::Fiber or what not. GL! -r
OTHER TIPS
Check out Green Shoes.
It's functionality is based off of _why's original implementation, but it's packaged as a Gem and built specifically for 1.9.
So I jumped into freenode #shoes and found out that the nightly build of shoes is using Ruby1.9. I haven't had time to try building it yet, but that should solve my problem.