小编edx*_*edx的帖子

在ruby的两个日期之间创建一个月的范围

我需要每月创建一个月份的日志文件.因此,我需要在给定范围内的所有[年,月]元组

你如何迭代日期?

如果我每天需要迭代,怎么办呢?

ruby loops date range

11
推荐指数
2
解决办法
9538
查看次数

如何从蛋白石调用原生javascript方法?

我正在编写一个基于html画布的简单游戏.我现在正从coffeescript移植到蛋白石.

我想以有效的方式包装CanvasRenderingContext2D对象.

我目前的解决方案是一个包装器,但我真的想让这个免费的桥接器.

app.rb:

class Game
    def initialize
        @canvas = Element.find('#canvas').get(0)
        js_ctx  = `this.canvas.getContext('2d')`        # this is a javascript object
        @ctx    = CanvasRenderingContext2D.new(js_ctx)  # create the proxy
        @ctx.fillStyle='red'
        @ctx.fillRect(10,10,50,50)
    end
end

# the opal proxy class (named $CanvasRenderingContext2D in javascript space)
class CanvasRenderingContext2D
    # I currently model the proxy as a has_a while I'd prefer it to be is_a
    attr_reader :js    # the native javascript object

    def initialize(js)
        @js = js
    end

    # getter
    def fillStyle
        `this.js.fillStyle`
    end

    # setter …
Run Code Online (Sandbox Code Playgroud)

ruby opalrb

5
推荐指数
1
解决办法
1120
查看次数

标签 统计

ruby ×2

date ×1

loops ×1

opalrb ×1

range ×1