如何将 Ruby1.9 与 Shoes 一起使用?
Shoes 包装了它自己的 Ruby 安装,对吗?
我无法使用 Fiber,这是 Ruby1.9 的一项功能。而且,我想使用 Fiber 来创建发电机。
这是我的代码(这样你就可以确保问题不在于我的代码):
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
如果我制作了一个这样的鞋子应用程序:
Shoes.app do
@b = BrownianGenerator.new
end
如果我拉起鞋子控制台,我会看到错误:
uninitialized constant #<class:0xblah>::BrownianGenerator::Fiber
因为,它说 Fiber 是未初始化的常量,要么我的代码有问题,要么这个 Ruby 版本不知道 Fiber 类 - 后者应该是这种情况。
我看到这个关于确定版本的问题Ruby(我的 mac 安装版本是 1.8),但我不知道如何更改版本。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看绿鞋。
它的功能基于 _why 的原始实现,但它被打包为 Gem 并专门为 1.9 构建。
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.
或者你可以使用阿曼古普塔的“穷人的纤维”或尝试做::Fiber
或者什么不是。
GL!
-r
or you could use aman gupta's "poor man's fibers" or try doing ::Fiber
or what not.
GL!
-r
所以我跳进了 freenode #shoes 并发现 nightly 版本的 Shoes 使用的是 Ruby1.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.